Migration from Amazon MWS to Selling Partner API

This commit is contained in:
Bobbie Hodgetts
2024-04-11 12:26:13 +01:00
committed by GitHub
parent e054278cdd
commit a7bc00e73a
1318 changed files with 2778105 additions and 5936 deletions

View File

@@ -8,76 +8,53 @@ namespace bnhtrade.Core.Logic.Account
{
public class GetAccountCodeInfo
{
private string sqlConnectionString;
private Data.Database.Account.ReadAccountCode readAccountCode;
private Dictionary<int, Model.Account.AccountCode> cache;
public GetAccountCodeInfo(string sqlConnectionString)
public GetAccountCodeInfo()
{
this.sqlConnectionString = sqlConnectionString;
readAccountCode = new Data.Database.Account.ReadAccountCode(sqlConnectionString);
cache = new Dictionary<int, Model.Account.AccountCode>();
readAccountCode = new Data.Database.Account.ReadAccountCode();
}
public void CacheClear()
public List<Model.Account.AccountCode> GetAll()
{
cache.Clear();
return readAccountCode.All();
}
public void CacheFill()
public Model.Account.AccountCode ByAccountCode(int accountCode)
{
CacheClear();
var resultList = readAccountCode.All();
foreach (var result in resultList)
var list = ByAccountCode(new List<int> { accountCode });
if (list.Any())
{
cache.Add(result.AccountCodeId, result);
}
}
public void CacheFill(List<int> accountCodeList, bool forceDbRead = false)
{
if (accountCodeList == null || !accountCodeList.Any())
{
return;
}
var accountCodeQueryList = new List<int>();
foreach (var code in accountCodeList.Distinct().ToList())
{
if (forceDbRead)
{
cache.Remove(code);
accountCodeQueryList.Add(code);
}
else if (!cache.ContainsKey(code))
{
accountCodeQueryList.Add(code);
}
}
// get db list
var dbList = readAccountCode.ByAccountCode(accountCodeQueryList);
// add to cache
foreach (var item in dbList)
{
cache.Add(item.AccountCodeId, item);
}
}
public Model.Account.AccountCode ByAccountCode(int accountCode, bool forceDbRead = false)
{
CacheFill(new List<int> { accountCode }, forceDbRead);
if (cache.ContainsKey(accountCode))
{
return cache[accountCode];
return list[0];
}
else
{
return null;
}
}
public List<Model.Account.AccountCode> ByAccountCode(List<int> accountCodeList)
{
return readAccountCode.ByAccountCode(accountCodeList);
}
public Dictionary<int, Model.Account.AccountCode> ConvertToDictionary(List<Model.Account.AccountCode> accountCodeList)
{
var returnDict = new Dictionary<int, Model.Account.AccountCode>();
if (accountCodeList == null)
{
return returnDict;
}
foreach (var accountCode in accountCodeList)
{
if (!returnDict.ContainsKey(accountCode.AccountCodeId))
{
returnDict.Add(accountCode.AccountCodeId, accountCode);
}
}
return returnDict;
}
}
}
}

View File

@@ -8,20 +8,18 @@ namespace bnhtrade.Core.Logic.Account
{
public class GetInvoiceLineItem
{
string sqlConnectionString;
private Dictionary<string, Model.Account.InvoiceLineItem> cache;
private Data.Database.Account.ReadInvoiceLineItem dbRead;
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
private Logic.Account.GetTaxCodeInfo getTaxCode;
private Logic.Account.GetAccountCodeInfo getAccountCode;
public GetInvoiceLineItem(string sqlConnectionString)
public GetInvoiceLineItem()
{
this.sqlConnectionString = sqlConnectionString;
CacheInnit();
dbRead = new Data.Database.Account.ReadInvoiceLineItem(sqlConnectionString);
getAccountCode = new GetAccountCodeInfo(sqlConnectionString);
getTaxCode = new GetTaxCodeInfo(sqlConnectionString);
dbRead = new Data.Database.Account.ReadInvoiceLineItem();
getAccountCode = new GetAccountCodeInfo();
getTaxCode = new GetTaxCodeInfo();
}
/// <summary>
@@ -63,21 +61,21 @@ namespace bnhtrade.Core.Logic.Account
// query database
var resultList = dbRead.ByItemCode(itemCodeQueryList);
// fill account & tax codes cache
getAccountCode.CacheFill(dbRead.AccountCodeList.Values.ToList(), forceDbRead);
getTaxCode.CacheFill(dbRead.TaxCodeList.Values.ToList(), forceDbRead);
// get account & tax codes dictionaries
var accountCodeDict = getAccountCode.ConvertToDictionary(getAccountCode.ByAccountCode(dbRead.AccountCodeList.Values.ToList()));
var taxCodeDict = getTaxCode.ConvertToDictionary(getTaxCode.GetByTaxCode(dbRead.TaxCodeList.Values.ToList()));
// build final itemcode object and add to cache
foreach (var result in resultList.Values)
{
if (dbRead.AccountCodeList.ContainsKey(result.ItemCode))
{
result.DefaultAccountCode = getAccountCode.ByAccountCode(dbRead.AccountCodeList[result.ItemCode]);
result.DefaultAccountCode = accountCodeDict[dbRead.AccountCodeList[result.ItemCode]];
}
if (dbRead.TaxCodeList.ContainsKey(result.ItemCode))
{
result.DefaultTaxCode = getTaxCode.GetByTaxCode(dbRead.TaxCodeList[result.ItemCode]);
result.DefaultTaxCode = taxCodeDict[dbRead.TaxCodeList[result.ItemCode]];
}
cache.Add(result.ItemCode, result);
@@ -91,7 +89,7 @@ namespace bnhtrade.Core.Logic.Account
/// <returns></returns>
public Model.Account.InvoiceLineItem CreateDefault(string itemCode)
{
new Data.Database.Account.CreateInvoiceLineItem(sqlConnectionString).CreateDefault(itemCode);
new Data.Database.Account.CreateInvoiceLineItem().CreateDefault(itemCode);
var item = dbRead.ByItemCode(itemCode);
cache.Add(item.ItemCode, item);
return item;

View File

@@ -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;
}
}
}
}