This commit is contained in:
2020-01-27 18:05:14 +00:00
parent 629cc300e4
commit eaefc5649b
5 changed files with 43 additions and 46 deletions

View File

@@ -306,7 +306,7 @@ namespace AyaNova.Api.Controllers
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDelete, dbObj.DisplayFileName), ct); EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDelete, dbObj.DisplayFileName), ct);
//Delete search index //Delete search index
Search.ProcessDeletedObjectKeywords(dbObj.Id, AyaType.FileAttachment); Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, AyaType.FileAttachment);
return NoContent(); return NoContent();
} }

View File

@@ -109,7 +109,7 @@ namespace AyaNova.Api.Controllers
try try
{ {
if (!biz.Put(o, inObj)) if (!biz.PutAsync(o, inObj))
return BadRequest(new ApiErrorResponse(biz.Errors)); return BadRequest(new ApiErrorResponse(biz.Errors));
} }
catch (DbUpdateConcurrencyException) catch (DbUpdateConcurrencyException)
@@ -155,7 +155,7 @@ namespace AyaNova.Api.Controllers
try try
{ {
//patch and validate //patch and validate
if (!biz.Patch(o, objectPatch, concurrencyToken)) if (!biz.PatchAsync(o, objectPatch, concurrencyToken))
return BadRequest(new ApiErrorResponse(biz.Errors)); return BadRequest(new ApiErrorResponse(biz.Errors));
} }
catch (DbUpdateConcurrencyException) catch (DbUpdateConcurrencyException)
@@ -262,7 +262,7 @@ namespace AyaNova.Api.Controllers
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType)) if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse()); return StatusCode(403, new ApiNotAuthorizedResponse());
if (!biz.Delete(o)) if (!biz.DeleteAsync(o))
return BadRequest(new ApiErrorResponse(biz.Errors)); return BadRequest(new ApiErrorResponse(biz.Errors));
return NoContent(); return NoContent();

View File

@@ -446,12 +446,12 @@ namespace AyaNova.Biz
ProcessKeywords(searchIndexObjectParameters, false);//localeId, objectID, objectType, false, name, text); ProcessKeywords(searchIndexObjectParameters, false);//localeId, objectID, objectType, false, name, text);
} }
public static void ProcessDeletedObjectKeywords(long objectID, AyaType objectType) public static async Task ProcessDeletedObjectKeywordsAsync(long objectID, AyaType objectType)
{ {
//Be careful in future, if you put ToString at the end of each object in the string interpolation //Be careful in future, if you put ToString at the end of each object in the string interpolation
//npgsql driver will assume it's a string and put quotes around it triggering an error that a string can't be compared to an int //npgsql driver will assume it's a string and put quotes around it triggering an error that a string can't be compared to an int
AyContext ct = ServiceProviderProvider.DBContext; AyContext ct = ServiceProviderProvider.DBContext;
ct.Database.ExecuteSqlInterpolated($"delete from asearchkey where objectid={objectID} and objecttype={(int)objectType}"); await ct.Database.ExecuteSqlInterpolatedAsync($"delete from asearchkey where objectid={objectID} and objecttype={(int)objectType}");
} }
@@ -477,7 +477,7 @@ namespace AyaNova.Biz
//IF NOT NEW, DELETE ALL EXISTING ENTRIES FOR OBJECT TYPE AND ID //IF NOT NEW, DELETE ALL EXISTING ENTRIES FOR OBJECT TYPE AND ID
if (!newRecord) if (!newRecord)
{ {
ProcessDeletedObjectKeywords(p.ObjectId, p.ObjectType); ProcessDeletedObjectKeywordsAsync(p.ObjectId, p.ObjectType);
} }
//BREAK OBJECT TEXT STRINGS INTO KEYWORD LIST //BREAK OBJECT TEXT STRINGS INTO KEYWORD LIST

View File

@@ -381,7 +381,7 @@ namespace AyaNova.Biz
EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct); EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
ct.SaveChanges(); ct.SaveChanges();
Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType); Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags); TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
return true; return true;

View File

@@ -56,7 +56,7 @@ namespace AyaNova.Biz
if (log && ret != null) if (log && ret != null)
{ {
//Log //Log
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
} }
return ret; return ret;
} }
@@ -85,9 +85,9 @@ namespace AyaNova.Biz
await ct.Widget.AddAsync(outObj); await ct.Widget.AddAsync(outObj);
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
//Handle child and associated items: //Handle child and associated items:
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
SearchIndex(outObj, true); await SearchIndex(outObj, true);
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null); await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
return outObj; return outObj;
} }
@@ -116,9 +116,9 @@ namespace AyaNova.Biz
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
//Handle child and associated items: //Handle child and associated items:
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
SearchIndex(outObj, true); await SearchIndex(outObj, true);
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null); await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
return outObj; return outObj;
} }
@@ -128,7 +128,7 @@ namespace AyaNova.Biz
// //
//put //put
internal bool Put(Widget dbObj, Widget inObj) internal async Task<bool> PutAsync(Widget dbObj, Widget inObj)
{ {
//make a snapshot of the original for validation but update the original to preserve workflow //make a snapshot of the original for validation but update the original to preserve workflow
@@ -151,15 +151,15 @@ namespace AyaNova.Biz
return false; return false;
//Log event and save context //Log event 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);
SearchIndex(dbObj, false); await SearchIndex(dbObj, false);
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags); await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
return true; return true;
} }
//patch //patch
internal bool Patch(Widget dbObj, JsonPatchDocument<Widget> objectPatch, uint concurrencyToken) internal async Task<bool> PatchAsync(Widget dbObj, JsonPatchDocument<Widget> objectPatch, uint concurrencyToken)
{ {
//Validate Patch is allowed //Validate Patch is allowed
//Note: Id and Serial are all checked for and disallowed in the validate code by default //Note: Id and Serial are all checked for and disallowed in the validate code by default
@@ -181,16 +181,16 @@ namespace AyaNova.Biz
return false; return false;
//Log event and save context //Log event 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);
SearchIndex(dbObj, false); await SearchIndex(dbObj, false);
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags); await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
return true; return true;
} }
private void SearchIndex(Widget obj, bool isNew) private async Task SearchIndex(Widget obj, bool isNew)
{ {
//SEARCH INDEXING //SEARCH INDEXING
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, obj.Id, BizType, obj.Name); var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, obj.Id, BizType, obj.Name);
@@ -198,31 +198,30 @@ namespace AyaNova.Biz
if (isNew) if (isNew)
Search.ProcessNewObjectKeywords(SearchParams); await Search.ProcessNewObjectKeywords(SearchParams);
else else
Search.ProcessUpdatedObjectKeywords(SearchParams); await Search.ProcessUpdatedObjectKeywords(SearchParams);
} }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//DELETE //DELETE
// //
internal bool Delete(Widget dbObj) internal async Task<bool> DeleteAsync(Widget dbObj)
{ {
//Determine if the object can be deleted, do the deletion tentatively //Determine if the object can be deleted, do the deletion tentatively
//Probably also in here deal with tags and associated search text etc //Probably also in here deal with tags and associated search text etc
ValidateCanDelete(dbObj); //NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
if (HasErrors) if (HasErrors)
return false; return false;
ct.Widget.Remove(dbObj); ct.Widget.Remove(dbObj);
ct.SaveChanges(); await ct.SaveChangesAsync();
//Log event and save context //Log event
EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct); await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
ct.SaveChanges(); await Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType); await TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
return true; return true;
} }
@@ -233,7 +232,7 @@ namespace AyaNova.Biz
// //
//Can save or update? //Can save or update?
private void Validate(Widget proposedObj, Widget currentObj) private async Task Validate(Widget proposedObj, Widget currentObj)
{ {
//NOTE: In DB schema only name and serial are not nullable //NOTE: In DB schema only name and serial are not nullable
@@ -253,7 +252,7 @@ namespace AyaNova.Biz
if (!PropertyHasErrors("Name")) if (!PropertyHasErrors("Name"))
{ {
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
if (ct.Widget.Any(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id)) if (await ct.Widget.AnyAsync(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
{ {
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name"); AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
} }
@@ -280,7 +279,7 @@ namespace AyaNova.Biz
} }
//Any form customizations to validate? //Any form customizations to validate?
var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == AyaFormFieldDefinitions.WIDGET_KEY); var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(x => x.FormKey == AyaFormFieldDefinitions.WIDGET_KEY);
if (FormCustomization != null) if (FormCustomization != null)
{ {
//Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required //Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required
@@ -292,16 +291,14 @@ namespace AyaNova.Biz
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields); CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
} }
return;
} }
//Can delete? //Can delete?
private void ValidateCanDelete(Widget inObj) // private void ValidateCanDelete(Widget inObj)
{ // {
//whatever needs to be check to delete this object // //whatever needs to be check to delete this object
} // }