mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 07:17:15 +00:00
Migration from Amazon MWS to Selling Partner API
This commit is contained in:
@@ -8,86 +8,29 @@ namespace bnhtrade.Core.Logic.Account
|
||||
{
|
||||
public class GetTaxCodeInfo
|
||||
{
|
||||
string sqlConnectionString;
|
||||
private bool allRetrived;
|
||||
private Dictionary<string, Model.Account.TaxCodeInfo> cache;
|
||||
private Dictionary<string, Model.Account.TaxCodeInfo> cacheInvoiceItem;
|
||||
private Data.Database.Account.ReadTaxCode dbRead;
|
||||
|
||||
public GetTaxCodeInfo(string sqlConnectionString)
|
||||
public GetTaxCodeInfo()
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
allRetrived = false;
|
||||
CacheClear();
|
||||
dbRead = new Data.Database.Account.ReadTaxCode(sqlConnectionString);
|
||||
}
|
||||
|
||||
private void CacheClear()
|
||||
{
|
||||
cache = new Dictionary<string, Model.Account.TaxCodeInfo>();
|
||||
cacheInvoiceItem = new Dictionary<string, Model.Account.TaxCodeInfo>();
|
||||
}
|
||||
|
||||
public void CacheFill()
|
||||
{
|
||||
CacheClear();
|
||||
|
||||
var list = dbRead.GetAllActive();
|
||||
foreach (var item in list)
|
||||
{
|
||||
cache.Add(item.TaxCode, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void CacheFill(List<string> taxCodeList, bool forceDbRead = false)
|
||||
{
|
||||
if (taxCodeList == null || !taxCodeList.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var taxCodeQueryList = new List<string>();
|
||||
foreach (var code in taxCodeList.Distinct().ToList())
|
||||
{
|
||||
if (forceDbRead)
|
||||
{
|
||||
cache.Remove(code);
|
||||
taxCodeQueryList.Add(code);
|
||||
}
|
||||
else if (!cache.ContainsKey(code))
|
||||
{
|
||||
taxCodeQueryList.Add(code);
|
||||
}
|
||||
}
|
||||
|
||||
// get db list
|
||||
var dbList = dbRead.GetByTaxCode(taxCodeQueryList);
|
||||
|
||||
// add to cache
|
||||
foreach (var item in dbList)
|
||||
{
|
||||
cache.Add(item.TaxCode, item);
|
||||
}
|
||||
dbRead = new Data.Database.Account.ReadTaxCode();
|
||||
}
|
||||
|
||||
public List<Model.Account.TaxCodeInfo> GetAllActive()
|
||||
{
|
||||
CacheFill();
|
||||
return cache.Values.ToList();
|
||||
return dbRead.GetAllActive();
|
||||
}
|
||||
|
||||
public Model.Account.TaxCodeInfo GetByTaxCode(string taxCode, bool forceDbRead = false)
|
||||
public List<Model.Account.TaxCodeInfo> GetByTaxCode(List<string> taxCodeList)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(taxCode))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return dbRead.GetByTaxCode(taxCodeList);
|
||||
}
|
||||
|
||||
CacheFill(new List<string> { taxCode }, forceDbRead);
|
||||
|
||||
if (cache.ContainsKey(taxCode))
|
||||
public Model.Account.TaxCodeInfo GetByTaxCode(string taxCode)
|
||||
{
|
||||
var temp = GetByTaxCode(new List<string> { taxCode });
|
||||
if (temp.Any())
|
||||
{
|
||||
return cache[taxCode];
|
||||
return temp[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,17 +52,9 @@ namespace bnhtrade.Core.Logic.Account
|
||||
return returnList;
|
||||
}
|
||||
|
||||
// remove any duplicates
|
||||
var cleanSkuList = skuNumberList.Distinct().ToList();
|
||||
|
||||
// get db list
|
||||
var dbList = dbRead.GetTaxCodeBySkuNumber(skuNumberList);
|
||||
|
||||
if (!dbList.Any()) { return returnList; }
|
||||
|
||||
// charge the cache
|
||||
dbRead.GetAllActive();
|
||||
|
||||
// build dictionary
|
||||
foreach (var item in dbList)
|
||||
{
|
||||
@@ -133,9 +68,50 @@ namespace bnhtrade.Core.Logic.Account
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public Dictionary<string, Model.Account.TaxCodeInfo> Get(List<Model.Account.InvoiceLineItem> invoiceLineList)
|
||||
public bool AddToSkuInfo(List<Model.Sku.Sku> skuList)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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<string, Model.Account.TaxCodeInfo> ConvertToDictionary(List<Model.Account.TaxCodeInfo> taxCodeList)
|
||||
{
|
||||
var returnDict = new Dictionary<string, Model.Account.TaxCodeInfo>();
|
||||
|
||||
if (taxCodeList == null)
|
||||
{
|
||||
return returnDict;
|
||||
}
|
||||
|
||||
foreach (var taxCode in taxCodeList)
|
||||
{
|
||||
if (!returnDict.ContainsKey(taxCode.TaxCode))
|
||||
{
|
||||
returnDict.Add(taxCode.TaxCode, taxCode);
|
||||
}
|
||||
}
|
||||
return returnDict;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user