|
@ -181,32 +181,38 @@ namespace ServerManager.SyncMethods |
|
|
} |
|
|
} |
|
|
private async Task SyncProductAltUnitAsync() |
|
|
private async Task SyncProductAltUnitAsync() |
|
|
{ |
|
|
{ |
|
|
var responseMessage = await m_httpClient.GetAsync("/api/SyncProducts/lastsyncdate/productaltunit"); |
|
|
try |
|
|
if (!responseMessage.IsSuccessStatusCode) |
|
|
|
|
|
{ |
|
|
{ |
|
|
return; |
|
|
var responseMessage = await m_httpClient.GetAsync("/api/SyncProducts/lastsyncdate/productaltunit"); |
|
|
} |
|
|
if (!responseMessage.IsSuccessStatusCode) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
DateTime date = await responseMessage.Content.ReadFromJsonAsync<DateTime>(); |
|
|
DateTime date = await responseMessage.Content.ReadFromJsonAsync<DateTime>(); |
|
|
IEnumerable<RestockLevel> modifiedCart = await m_productService.FetchRestockAsync(date, "BRID0"); |
|
|
IEnumerable<ProductAltUnit> modifiedCart = await m_productService.FetchProductAltUnit(date, "BRID0"); |
|
|
SyncTimestamp syncTimestamp = new SyncTimestamp { TableName = "productaltunit", Timestamp = DateTime.Now.AddSeconds(-10) }; |
|
|
SyncTimestamp syncTimestamp = new SyncTimestamp { TableName = "productaltunit", Timestamp = DateTime.Now.AddSeconds(-10) }; |
|
|
int batchSize = 200; |
|
|
int batchSize = 200; |
|
|
int totalItems = modifiedCart.Count(); |
|
|
int totalItems = modifiedCart.Count(); |
|
|
int batches = (totalItems + batchSize - 1) / batchSize; // Calculate total batches
|
|
|
int batches = (totalItems + batchSize - 1) / batchSize; // Calculate total batches
|
|
|
|
|
|
|
|
|
for (int batchIndex = 0; batchIndex < batches; batchIndex++) |
|
|
for (int batchIndex = 0; batchIndex < batches; batchIndex++) |
|
|
{ |
|
|
|
|
|
List<RestockLevel> batch = modifiedCart.Skip(batchIndex * batchSize).Take(batchSize).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblProductAltUnit", batch); |
|
|
|
|
|
if (response.IsSuccessStatusCode) |
|
|
|
|
|
{ |
|
|
{ |
|
|
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); |
|
|
List<ProductAltUnit> batch = modifiedCart.Skip(batchIndex * batchSize).Take(batchSize).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblProductAltUnit", batch); |
|
|
|
|
|
if (response.IsSuccessStatusCode) |
|
|
|
|
|
{ |
|
|
|
|
|
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Set last sync date
|
|
|
//Set last sync date
|
|
|
await m_httpClient.PostAsJsonAsync("/api/SyncProducts/setsyncdate", syncTimestamp); |
|
|
await m_httpClient.PostAsJsonAsync("/api/SyncProducts/setsyncdate", syncTimestamp); |
|
|
|
|
|
}catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
private async Task SyncStockAsync() |
|
|
private async Task SyncStockAsync() |
|
|
{var responseMessage = await m_httpClient.GetAsync("/api/SyncProducts/lastsyncdate/tbstock"); |
|
|
{var responseMessage = await m_httpClient.GetAsync("/api/SyncProducts/lastsyncdate/tbstock"); |
|
|