This commit is contained in:
2021-06-30 18:24:30 +00:00
parent ad50aeac4a
commit 41da081ce5
4 changed files with 85 additions and 7 deletions

View File

@@ -37,10 +37,50 @@ namespace AyaNova.Biz
//UPDATE
//
//Creating a user creates a user options so no need for create ever
// ////////////////////////////////////////////////////////////////////////////////////////////////
// //CREATE
// //
// internal async Task<UserOptions> CreateAsync(UserOptions newObject)
// {
// User u = await ct.User.AsNoTracking().SingleOrDefaultAsync(z => z.Id == newObject.UserId);
// if (u == null)
// {
// AddError(ApiErrorCode.NOT_FOUND, "id");
// return null;
// }
// //Also used for Contacts (customer type user or ho type user)
// //by users with no User right but with Customer rights so need to double check here
// if (
// (u.IsOutsideUser && !Authorized.HasModifyRole(CurrentUserRoles, AyaType.Customer)) ||
// (!u.IsOutsideUser && !Authorized.HasModifyRole(CurrentUserRoles, AyaType.User))
// )
// {
// AddError(ApiErrorCode.NOT_AUTHORIZED);
// return null;
// }
// Validate(newObject);
// if (HasErrors)
// return null;
// else
// {
// await ct.UserOptions.AddAsync(newObject);
// await ct.SaveChangesAsync();
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
// return newObject;
// }
// }
//put
internal async Task<bool> PutAsync(UserOptions dbObject, UserOptions inObj)
{
//todo: update to use the new PUT methodology?
//if it's not the user's own options then we need to check it just as for User / Contact objects
if (dbObject.Id != UserId)
{
@@ -66,7 +106,9 @@ namespace AyaNova.Biz
CopyObject.Copy(inObj, dbObject, "Id, UserId");
//Set "original" value of concurrency token to input token
//this will allow EF to check it out
ct.Entry(dbObject).OriginalValues["Concurrency"] = inObj.Concurrency;
//BUT NOT IF IT"S FROM A DUPLICATION OP (CONCURRENCY=0)
if (inObj.Concurrency != 0)
ct.Entry(dbObject).OriginalValues["Concurrency"] = inObj.Concurrency;
Validate(dbObject);
if (HasErrors)