mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 06:27:15 +00:00
wip
This commit is contained in:
@@ -190,87 +190,18 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
}
|
||||
// finish loop
|
||||
|
||||
// validate and save values to database
|
||||
var validate = new Core.Logic.Validate.SkuPriceInfo();
|
||||
if (!validate.IsValidDatabaseCreate(crDictionary.Values.ToList()))
|
||||
{
|
||||
err += "Database object create validation failed";
|
||||
log.LogError(err, validate.ValidationResultListToString());
|
||||
throw new Exception(err);
|
||||
}
|
||||
// save values to database
|
||||
SaveToDatabase(crDictionary);
|
||||
|
||||
new Data.Database.Sku.Price.CreatePricingDetail(sqlConnectionString).Executue(crDictionary.Values.ToList());
|
||||
// upload to amazon
|
||||
UploadToAmazon(crDictionary);
|
||||
|
||||
// create and upload inventory loader file to amazon
|
||||
var exportList = new List<Model.Export.AmazonIventoryLoaderFile>();
|
||||
foreach (var item in crDictionary.Values)
|
||||
{
|
||||
var listItem = new Model.Export.AmazonIventoryLoaderFile();
|
||||
listItem.Sku = item.SkuNumber;
|
||||
listItem.MinimumAllowedPrice = item.MinPrice;
|
||||
listItem.MaximumAllowedPrice = item.MaxPrice;
|
||||
listItem.Price = item.MaxPrice;
|
||||
listItem.SetFulfillmentCenterId(true);
|
||||
exportList.Add(listItem);
|
||||
}
|
||||
|
||||
// validate
|
||||
var vaildateInvLoader = new Validate.AmazonIventoryLoaderFile();
|
||||
if (!vaildateInvLoader.IsValidFbaPricing(exportList))
|
||||
{
|
||||
err += "Inventory loader object validation failed";
|
||||
log.LogError(err, vaildateInvLoader.ValidationResultListToString());
|
||||
throw new Exception(err);
|
||||
}
|
||||
|
||||
// create file stream
|
||||
var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.CurrentCulture);
|
||||
config.Delimiter = "\t";
|
||||
config.Encoding = Encoding.UTF8;
|
||||
|
||||
var stream = new MemoryStream();
|
||||
using (var writer = new StreamWriter(stream, Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
csv.WriteRecords(exportList);
|
||||
}
|
||||
|
||||
// submit file to database and amazon mws
|
||||
var submit = new Logic.Export.AmazonSubmitFile(sqlConnectionString);
|
||||
|
||||
return;
|
||||
|
||||
submit.SubmitInventoryLoader(stream);
|
||||
return; // remove after testing
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
private bool OkayToReprice(DateTime lastPriceUpdate)
|
||||
{
|
||||
if (lastPriceUpdate == default(DateTime))
|
||||
{
|
||||
err += "Invalid, datetime is default.";
|
||||
log.LogError(err);
|
||||
throw new Exception(err);
|
||||
}
|
||||
|
||||
bool update = false;
|
||||
lastPriceUpdate = new DateTime(lastPriceUpdate.Year, lastPriceUpdate.Month, lastPriceUpdate.Day);
|
||||
DateTime today = new DateTime(newTimeStamp.Year, newTimeStamp.Month, newTimeStamp.Day);
|
||||
|
||||
// will only update once on tue, wed or thurs each week.
|
||||
if (today.DayOfWeek == DayOfWeek.Tuesday || today.DayOfWeek == DayOfWeek.Wednesday || today.DayOfWeek == DayOfWeek.Thursday)
|
||||
{
|
||||
if (today > lastPriceUpdate.AddDays(3))
|
||||
{
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
return update;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the minimum sale price to break even.
|
||||
/// </summary>
|
||||
@@ -382,6 +313,44 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
}
|
||||
}
|
||||
|
||||
private bool OkayToReprice(DateTime lastPriceUpdate)
|
||||
{
|
||||
if (lastPriceUpdate == default(DateTime))
|
||||
{
|
||||
err += "Invalid, datetime is default.";
|
||||
log.LogError(err);
|
||||
throw new Exception(err);
|
||||
}
|
||||
|
||||
bool update = false;
|
||||
lastPriceUpdate = new DateTime(lastPriceUpdate.Year, lastPriceUpdate.Month, lastPriceUpdate.Day);
|
||||
DateTime today = new DateTime(newTimeStamp.Year, newTimeStamp.Month, newTimeStamp.Day);
|
||||
|
||||
// will only update once on tue, wed or thurs each week.
|
||||
if (today.DayOfWeek == DayOfWeek.Tuesday || today.DayOfWeek == DayOfWeek.Wednesday || today.DayOfWeek == DayOfWeek.Thursday)
|
||||
{
|
||||
if (today > lastPriceUpdate.AddDays(3))
|
||||
{
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
return update;
|
||||
}
|
||||
|
||||
private void SaveToDatabase(Dictionary<string, Model.Sku.Price.PriceInfo> crDictionary)
|
||||
{
|
||||
var validate = new Core.Logic.Validate.SkuPriceInfo();
|
||||
if (!validate.IsValidDatabaseCreate(crDictionary.Values.ToList()))
|
||||
{
|
||||
err += "Database object create validation failed";
|
||||
log.LogError(err, validate.ValidationResultListToString());
|
||||
throw new Exception(err);
|
||||
}
|
||||
|
||||
new Data.Database.Sku.Price.CreatePricingDetail(sqlConnectionString).Executue(crDictionary.Values.ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Before running reprice update, this method ensures that the relevant data needed is up to date.
|
||||
/// </summary>
|
||||
@@ -396,5 +365,48 @@ namespace bnhtrade.Core.Logic.Sku.Price
|
||||
|
||||
// check last amazon sku fees updates
|
||||
}
|
||||
|
||||
private void UploadToAmazon(Dictionary<string, Model.Sku.Price.PriceInfo> crDictionary)
|
||||
{
|
||||
var exportList = new List<Model.Export.AmazonIventoryLoaderFile>();
|
||||
foreach (var item in crDictionary.Values)
|
||||
{
|
||||
var listItem = new Model.Export.AmazonIventoryLoaderFile();
|
||||
listItem.Sku = item.SkuNumber;
|
||||
listItem.MinimumAllowedPrice = item.MinPrice;
|
||||
listItem.MaximumAllowedPrice = item.MaxPrice;
|
||||
listItem.Price = item.MaxPrice;
|
||||
listItem.SetFulfillmentCenterId(true);
|
||||
exportList.Add(listItem);
|
||||
}
|
||||
|
||||
// validate
|
||||
var vaildateInvLoader = new Validate.AmazonIventoryLoaderFile();
|
||||
if (!vaildateInvLoader.IsValidFbaPricing(exportList))
|
||||
{
|
||||
err += "Inventory loader object validation failed";
|
||||
log.LogError(err, vaildateInvLoader.ValidationResultListToString());
|
||||
throw new Exception(err);
|
||||
}
|
||||
|
||||
// create file stream
|
||||
var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.CurrentCulture);
|
||||
config.Delimiter = "\t";
|
||||
config.Encoding = Encoding.UTF8;
|
||||
|
||||
var stream = new MemoryStream();
|
||||
using (var writer = new StreamWriter(stream, Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
csv.WriteRecords(exportList);
|
||||
}
|
||||
|
||||
// submit file to database and amazon mws
|
||||
var submit = new Logic.Export.AmazonSubmitFile(sqlConnectionString);
|
||||
|
||||
return; // remove after testing
|
||||
|
||||
submit.SubmitInventoryLoader(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user