This commit is contained in:
@@ -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
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user