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