This commit is contained in:
2021-02-04 15:14:58 +00:00
parent 9f0c111d3d
commit 38f6cdf421
2 changed files with 34 additions and 49 deletions

View File

@@ -57,18 +57,8 @@ namespace AyaNova.Biz
//do stuff with datafilter
DataListSavedFilter outObj = inObj;
outObj.UserId = UserId;
await ct.DataListSavedFilter.AddAsync(outObj);
await ct.SaveChangesAsync();
//Handle child and associated items:
//EVENT LOG
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
return outObj;
}
@@ -85,11 +75,7 @@ namespace AyaNova.Biz
{
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
var ret = await ct.DataListSavedFilter.AsNoTracking().SingleOrDefaultAsync(z => z.Id == fetchId && (z.Public == true || z.UserId == UserId));
// if (logTheGetEvent && ret != null)
// {
// //Log
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
// }
return ret;
}
@@ -139,29 +125,38 @@ namespace AyaNova.Biz
//
//put
internal async Task<bool> PutAsync(DataListSavedFilter dbObject, DataListSavedFilter inObj)
internal async Task<DataListSavedFilter> PutAsync(DataListSavedFilter putObject)
{
//preserve the owner ID if none was specified
if (inObj.UserId == 0)
inObj.UserId = dbObject.UserId;
var dbObject = await GetAsync(putObject.Id);
if (dbObject == null)
{
AddError(ApiErrorCode.NOT_FOUND, "id");
return null;
}
//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;
//preserve the owner ID if none was specified
if (putObject.UserId == 0)
putObject.UserId = dbObject.UserId;
Validate(dbObject, false);
if (HasErrors)
return false;
await ct.SaveChangesAsync();
return null;
//Log modification and save context
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
ct.Replace(dbObject, putObject);
try
{
await ct.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!await ExistsAsync(putObject.Id))
AddError(ApiErrorCode.NOT_FOUND);
else
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
return null;
}
return true;
return dbObject;
}