This commit is contained in:
2021-01-19 21:47:30 +00:00
parent f78ed5e590
commit 8a52b60f2a
7 changed files with 68 additions and 12 deletions

View File

@@ -181,6 +181,57 @@ namespace AyaNova.Biz
}
////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATESERIALS
//
internal async Task<List<String>> PutSerialsAsync(long id, List<string> serials)
{
//Fixup serials
int nAdded = 0;
int nRemoved = 0;
var ExistingSerials = await ct.PartSerial.Where(z => z.PartId == id).OrderBy(z => z.Serial).ToListAsync();
//Remove any that should not be there anymore
foreach (PartSerial ps in ExistingSerials)
{
if (!serials.Contains(ps.Serial))
{
ct.PartSerial.Remove(ps);
nRemoved++;
}
}
//Add any new ones
foreach (string s in serials)
{
if (!ExistingSerials.Any(z => z.Serial == s))
{
ct.PartSerial.Add(new PartSerial() { Serial = s, 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
//