This commit is contained in:
2022-01-26 18:31:29 +00:00
parent e798abd2bc
commit 649bff878d
4 changed files with 77 additions and 34 deletions

View File

@@ -111,35 +111,67 @@ namespace AyaNova.Biz
////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE
//
//put
internal async Task<bool> PutAsync(FormCustom dbObject, FormCustom inObj)
internal async Task<FormCustom> PutAsync(FormCustom putObject)
{
//todo: replace with new put methodology
//Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObject, "Id");
//Set "original" value of concurrency token to input token
//this will allow EF to check it out
ct.Entry(dbObject).OriginalValues["Concurrency"] = inObj.Concurrency;
await ValidateAsync(dbObject, false);
var dbObject = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == putObject.FormKey);
if (dbObject == null)
{
AddError(ApiErrorCode.NOT_FOUND, "formKey");
return null;
}
if (dbObject.Concurrency != putObject.Concurrency)
{
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
return null;
}
dbObject.Template = JsonUtil.CompactJson(putObject.Template);
putObject.Id=dbObject.Id;//weird workaround needed because ID is not sent with the putobject for...reasons 🤷?
await ValidateAsync(putObject, false);
if (HasErrors)
return false;
dbObject.Template = JsonUtil.CompactJson(dbObject.Template);
await ct.SaveChangesAsync();
return null;
ct.Replace(dbObject, putObject);
try
{
await ct.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!await ExistsAsync(putObject.FormKey))
AddError(ApiErrorCode.NOT_FOUND);
else
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
return null;
}
//Log modification and save context
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
return putObject;
// //todo: replace with new put methodology
// //Replace the db object with the PUT object
// CopyObject.Copy(putObject, dbObject, "Id");
// //Set "original" value of concurrency token to input token
// //this will allow EF to check it out
// ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency;
// await ValidateAsync(dbObject, false);
// if (HasErrors)
// return false;
// dbObject.Template = JsonUtil.CompactJson(dbObject.Template);
// await ct.SaveChangesAsync();
// //Log modification and save context
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
return true;
// return true;
}