This commit is contained in:
2021-01-25 23:56:39 +00:00
parent c99498ba23
commit 7d3b630574

View File

@@ -244,15 +244,22 @@ namespace AyaNova.Biz
int nRemoved = 0;
var ExistingStockLevels = await ct.PartStockLevel.Where(z => z.PartId == id).ToListAsync();
//Remove any that should not be there anymore
//Remove any that should not be there anymore and update any that should
foreach (PartStockLevel existingPS in ExistingStockLevels)
{
if (!putPartStockLevels.Any(z => z.PartWarehouseId == existingPS.PartWarehouseId))
var putPS = putPartStockLevels.Where(z => z.PartWarehouseId == existingPS.PartWarehouseId).FirstOrDefault();
if (putPS == null)
{
//no longer in the collection so ditch it
//no longer in the existing collection so ditch it
ct.PartStockLevel.Remove(existingPS);
nRemoved++;
}
else
{
//still here, so update if necessary
existingPS.MinimumQuantity = putPS.MinimumQuantity;
}
}
//Add any new ones
@@ -260,7 +267,7 @@ namespace AyaNova.Biz
{
if (!ExistingStockLevels.Any(z => z.PartWarehouseId == putPS.PartWarehouseId))
{
ct.PartStockLevel.Add(new PartStockLevel() { PartWarehouseId = putPS.PartWarehouseId, PartId = id });
ct.PartStockLevel.Add(new PartStockLevel() { PartWarehouseId = putPS.PartWarehouseId, PartId = id, MinimumQuantity = putPS.MinimumQuantity });
nAdded++;
}
}
@@ -281,7 +288,13 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Modified, $"LT:PartStockingLevels change (+{nAdded}, -{nRemoved})"), ct);
return await ct.PartStockLevel.AsNoTracking().Where(z => z.PartId == id).OrderBy(z => z.PartWarehouseId).ToListAsync();
var ret = await ct.PartStockLevel.AsNoTracking().Where(z => z.PartId == id).OrderBy(z => z.PartWarehouseId).ToListAsync();
foreach (PartStockLevel ps in ret)
{
ps.PartWarehouseDisplay = await ct.PartWarehouse.AsNoTracking().Where(z => z.Id == ps.PartWarehouseId).Select(z => z.Name).FirstOrDefaultAsync();
}
return ret;
}
////////////////////////////////////////////////////////////////////////////////////////////////