This commit is contained in:
2021-01-25 19:52:22 +00:00
parent 936452cdb4
commit 887dbe5dd8
10 changed files with 153 additions and 20 deletions

View File

@@ -232,6 +232,58 @@ namespace AyaNova.Biz
}
////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE STOCK LEVELS
//
internal async Task<List<String>> PutStockLevelsAsync(long id, List<PartStockLevel> putPartStockLevels)
{
//Fixup serials
int nAdded = 0;
int nRemoved = 0;
var ExistingStockLevels = await ct.PartStockLevel.Where(z => z.PartId == id).ToListAsync();
//Remove any that should not be there anymore
foreach (PartStockLevel existingPS in ExistingStockLevels)
{
if (!putPartStockLevels.Any(z => z.PartWarehouseId==existingPS.PartWarehouseId))
{
//no longer in the collection so ditch it
ct.PartStockLevel.Remove(existingPS);
nRemoved++;
}
}
//Add any new ones
foreach (PartStockLevel putPS in putPartStockLevels)
{
if (!ExistingStockLevels.Any(z => z.PartWarehouseId==putPS.PartWarehouseId))
{
ct.PartStockLevel.Add(new PartStockLevel() { PartWarehouseId = putPS.PartWarehouseId, PartId = id });
nAdded++;
}
}
try
{
await ct.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!await ExistsAsync(id))
AddError(ApiErrorCode.NOT_FOUND);
else
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
return null;
}
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Modified, $"LT:PartSerialNumbersAvailable change (+{nAdded}, -{nRemoved})"), ct);
return await ct.PartSerial.Where(z => z.PartId == id).OrderBy(z => z.Serial).Select(z => z.Serial).ToListAsync();
}
////////////////////////////////////////////////////////////////////////////////////////////////
//SEARCH
//