This commit is contained in:
@@ -244,15 +244,22 @@ namespace AyaNova.Biz
|
|||||||
int nRemoved = 0;
|
int nRemoved = 0;
|
||||||
var ExistingStockLevels = await ct.PartStockLevel.Where(z => z.PartId == id).ToListAsync();
|
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)
|
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);
|
ct.PartStockLevel.Remove(existingPS);
|
||||||
nRemoved++;
|
nRemoved++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//still here, so update if necessary
|
||||||
|
existingPS.MinimumQuantity = putPS.MinimumQuantity;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add any new ones
|
//Add any new ones
|
||||||
@@ -260,7 +267,7 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (!ExistingStockLevels.Any(z => z.PartWarehouseId == putPS.PartWarehouseId))
|
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++;
|
nAdded++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,7 +288,13 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Modified, $"LT:PartStockingLevels change (+{nAdded}, -{nRemoved})"), ct);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user