using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace bnhtrade.Core.Logic.Account { public class GetTaxCodeInfo { private Data.Database.Account.ReadTaxCode dbRead; public GetTaxCodeInfo() { dbRead = new Data.Database.Account.ReadTaxCode(); } public List GetAllActive() { return dbRead.GetAllActive(); } public List GetByTaxCode(List taxCodeList) { return dbRead.GetByTaxCode(taxCodeList); } public Model.Account.TaxCodeInfo GetByTaxCode(string taxCode) { var temp = GetByTaxCode(new List { taxCode }); if (temp.Any()) { return temp[0]; } else { return null; } } /// /// Gets list of Tax Code Info for a given list of Sku Numbers /// /// List of SKU numbers /// Dictionary, key is SkuNumber and value is Tax Code Info public Dictionary GetBySkuNumber(List skuNumberList) { var returnList = new Dictionary(); if (skuNumberList == null || !skuNumberList.Any()) { return returnList; } // get db list var dbList = dbRead.GetTaxCodeBySkuNumber(skuNumberList); // build dictionary foreach (var item in dbList) { var taxInfo = GetByTaxCode(item.Value); if (taxInfo != null) { returnList.Add(item.Key, taxInfo); } } return returnList; } public bool AddToSkuInfo(List skuList) { bool missionSuccess = true; if (skuList == null || !skuList.Any()) { return true; } // get list of sku numbers to condition codes var lookupDictionary = GetBySkuNumber(skuList.Select(x => x.SkuNumber).ToList()); for (int i = 0; i < skuList.Count; i++) { if (lookupDictionary.ContainsKey(skuList[i].SkuNumber)) { skuList[i].TaxCodeInfo = lookupDictionary[skuList[i].SkuNumber]; } else { missionSuccess = false; } } return missionSuccess; } public Dictionary ConvertToDictionary(List taxCodeList) { var returnDict = new Dictionary(); if (taxCodeList == null) { return returnDict; } foreach (var taxCode in taxCodeList) { if (!returnDict.ContainsKey(taxCode.TaxCode)) { returnDict.Add(taxCode.TaxCode, taxCode); } } return returnDict; } } }