This commit is contained in:
@@ -124,7 +124,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
if (!biz.Put(o, inObj))
|
||||
if (!biz.PutAsync(o, inObj))
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
@@ -183,7 +183,7 @@ namespace AyaNova.Api.Controllers
|
||||
try
|
||||
{
|
||||
//patch and validate
|
||||
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
||||
if (!biz.PatchAsync(o, objectPatch, concurrencyToken))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
@@ -288,7 +288,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
if (!biz.Delete(dbObj))
|
||||
if (!biz.DeleteAsync(dbObj))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ namespace AyaNova.Biz
|
||||
if (inObj.UserOptions == null)
|
||||
inObj.UserOptions = new UserOptions();
|
||||
|
||||
|
||||
await ValidateAsync(inObj, null);
|
||||
if (HasErrors)
|
||||
return null;
|
||||
@@ -86,54 +85,54 @@ namespace AyaNova.Biz
|
||||
await SearchIndexAsync(inObj, true);
|
||||
|
||||
//TAGS
|
||||
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, inObj.Tags, null);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, inObj.Tags, null);
|
||||
|
||||
return inObj;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE
|
||||
internal User Create(AyContext TempContext, User inObj)
|
||||
{
|
||||
//This is a new user so it will have been posted with a password in plaintext which needs to be salted and hashed
|
||||
inObj.Salt = Hasher.GenerateSalt();
|
||||
inObj.Password = Hasher.hash(inObj.Salt, inObj.Password);
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //CREATE
|
||||
// internal User Create(AyContext TempContext, User inObj)
|
||||
// {
|
||||
// //This is a new user so it will have been posted with a password in plaintext which needs to be salted and hashed
|
||||
// inObj.Salt = Hasher.GenerateSalt();
|
||||
// inObj.Password = Hasher.hash(inObj.Salt, inObj.Password);
|
||||
|
||||
inObj.Tags = TagUtil.NormalizeTags(inObj.Tags);
|
||||
inObj.CustomFields = JsonUtil.CompactJson(inObj.CustomFields);
|
||||
// inObj.Tags = TagUtil.NormalizeTags(inObj.Tags);
|
||||
// inObj.CustomFields = JsonUtil.CompactJson(inObj.CustomFields);
|
||||
|
||||
//Seeder sets user options in advance so no need to create them here in that case
|
||||
if (inObj.UserOptions == null)
|
||||
inObj.UserOptions = new UserOptions();
|
||||
// //Seeder sets user options in advance so no need to create them here in that case
|
||||
// if (inObj.UserOptions == null)
|
||||
// inObj.UserOptions = new UserOptions();
|
||||
|
||||
ValidateAsync(inObj, null);
|
||||
if (HasErrors)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
// ValidateAsync(inObj, null);
|
||||
// if (HasErrors)
|
||||
// return null;
|
||||
// else
|
||||
// {
|
||||
|
||||
TempContext.User.Add(inObj);
|
||||
// TempContext.User.Add(inObj);
|
||||
|
||||
//save to get Id
|
||||
TempContext.SaveChanges();
|
||||
// //save to get Id
|
||||
// TempContext.SaveChanges();
|
||||
|
||||
//Handle child and associated items
|
||||
// //Handle child and associated items
|
||||
|
||||
//Log event
|
||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, inObj.Id, BizType, AyaEvent.Created), TempContext);
|
||||
// //Log event
|
||||
// EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, inObj.Id, BizType, AyaEvent.Created), TempContext);
|
||||
|
||||
//SEARCH INDEXING
|
||||
SearchIndexAsync(inObj, true);
|
||||
// //SEARCH INDEXING
|
||||
// SearchIndexAsync(inObj, true);
|
||||
|
||||
//TAGS
|
||||
TagUtil.ProcessUpdateTagsInRepositoryAsync(TempContext, inObj.Tags, null);
|
||||
// //TAGS
|
||||
// TagUtil.ProcessUpdateTagsInRepositoryAsync(TempContext, inObj.Tags, null);
|
||||
|
||||
return inObj;
|
||||
// return inObj;
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// GET
|
||||
@@ -146,7 +145,7 @@ namespace AyaNova.Biz
|
||||
if (ret != null)
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -266,7 +265,7 @@ namespace AyaNova.Biz
|
||||
//
|
||||
|
||||
//put
|
||||
internal bool Put(User dbObj, User inObj)
|
||||
internal async Task<bool> PutAsync(User dbObj, User inObj)
|
||||
{
|
||||
//Get a snapshot of the original db value object before changes
|
||||
User SnapshotOfOriginalDBObj = new User();
|
||||
@@ -295,23 +294,23 @@ namespace AyaNova.Biz
|
||||
//this will allow EF to check it out
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
||||
|
||||
ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Log modification and save context
|
||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
|
||||
SearchIndexAsync(dbObj, false);
|
||||
await SearchIndexAsync(dbObj, false);
|
||||
|
||||
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//patch
|
||||
internal bool Patch(User dbObj, JsonPatchDocument<User> objectPatch, uint concurrencyToken)
|
||||
internal async Task<bool> PatchAsync(User dbObj, JsonPatchDocument<User> objectPatch, uint concurrencyToken)
|
||||
{
|
||||
//Validate Patch is allowed
|
||||
if (!ValidateJsonPatch<User>.Validate(this, objectPatch)) return false;
|
||||
@@ -333,15 +332,16 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
|
||||
ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Log modification and save context
|
||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
SearchIndexAsync(dbObj, false);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
await SearchIndexAsync(dbObj, false);
|
||||
|
||||
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -363,25 +363,25 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal bool Delete(User dbObj)
|
||||
internal async Task<bool> DeleteAsync(User dbObj)
|
||||
{
|
||||
ValidateCanDelete(dbObj);
|
||||
await ValidateCanDelete(dbObj);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
//Remove the object
|
||||
ct.User.Remove(dbObj);
|
||||
ct.SaveChanges();
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Delete sibling objects
|
||||
//USEROPTIONS
|
||||
ct.Database.ExecuteSqlInterpolated($"delete from auseroptions where userid={dbObj.Id}");
|
||||
await ct.Database.ExecuteSqlInterpolatedAsync($"delete from auseroptions where userid={dbObj.Id}");
|
||||
|
||||
|
||||
EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
|
||||
ct.SaveChanges();
|
||||
Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
|
||||
TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
|
||||
|
||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
|
||||
await TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -556,7 +556,7 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
//Can delete?
|
||||
private void ValidateCanDelete(User inObj)
|
||||
private async Task ValidateCanDelete(User inObj)
|
||||
{
|
||||
|
||||
|
||||
@@ -569,7 +569,8 @@ namespace AyaNova.Biz
|
||||
//They can always make any user inactive to get rid of them and it will mean referential integrity issues are not there
|
||||
|
||||
//There's only one rule - have they done anything eventlog worthy yet?
|
||||
if (ct.Event.Select(m => m).Where(m => m.UserId == inObj.Id).Count() > 0)
|
||||
//if (await ct.Event.Select(m => m).Where(m => m.UserId == inObj.Id).Count() > 0)
|
||||
if (await ct.Event.AnyAsync(m => m.UserId == inObj.Id))
|
||||
{
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "user", "LT:ErrorDBForeignKeyViolation");
|
||||
return;
|
||||
@@ -829,7 +830,7 @@ namespace AyaNova.Biz
|
||||
break;
|
||||
case "eventlog":
|
||||
{
|
||||
ImportAyaNova7Biz.LogEventCreatedModifiedEventsAsync(j, importMap, BizType, ct);
|
||||
await ImportAyaNova7Biz.LogEventCreatedModifiedEventsAsync(j, importMap, BizType, ct);
|
||||
}
|
||||
break;
|
||||
case "locale":
|
||||
@@ -884,7 +885,7 @@ namespace AyaNova.Biz
|
||||
break;
|
||||
}
|
||||
|
||||
u.LocaleId = LocaleBiz.LocaleNameToIdStaticAsync(NewLocaleName, ct);
|
||||
u.LocaleId = await LocaleBiz.LocaleNameToIdStaticAsync(NewLocaleName, ct);
|
||||
|
||||
ct.SaveChanges();
|
||||
#endregion set locale
|
||||
|
||||
Reference in New Issue
Block a user