This commit is contained in:
2020-01-27 19:42:53 +00:00
parent aac23818fb
commit 1a322eaa10

View File

@@ -32,7 +32,7 @@ namespace AyaNova.Biz
}
//This is where active tech license consumers are accounted for
internal static async Task<long> ActiveCount()
internal static async Task<long> ActiveCountAsync()
{
var ct = ServiceProviderProvider.DBContext;
var ret = await ct.User.Where(x => x.Active == true && (x.UserType == UserType.Schedulable || x.UserType == UserType.Subcontractor)).LongCountAsync();
@@ -67,7 +67,7 @@ namespace AyaNova.Biz
inObj.UserOptions = new UserOptions();
Validate(inObj, null);
await ValidateAsync(inObj, null);
if (HasErrors)
return null;
else
@@ -80,10 +80,10 @@ namespace AyaNova.Biz
//Handle child and associated items
//Log event
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, inObj.Id, BizType, AyaEvent.Created), ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, inObj.Id, BizType, AyaEvent.Created), ct);
//SEARCH INDEXING
SearchIndex(inObj, true);
await SearchIndexAsync(inObj, true);
//TAGS
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, inObj.Tags, null);
@@ -108,7 +108,7 @@ namespace AyaNova.Biz
if (inObj.UserOptions == null)
inObj.UserOptions = new UserOptions();
Validate(inObj, null);
ValidateAsync(inObj, null);
if (HasErrors)
return null;
else
@@ -125,7 +125,7 @@ namespace AyaNova.Biz
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, inObj.Id, BizType, AyaEvent.Created), TempContext);
//SEARCH INDEXING
SearchIndex(inObj, true);
SearchIndexAsync(inObj, true);
//TAGS
TagUtil.ProcessUpdateTagsInRepositoryAsync(TempContext, inObj.Tags, null);
@@ -295,7 +295,7 @@ namespace AyaNova.Biz
//this will allow EF to check it out
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
Validate(dbObj, SnapshotOfOriginalDBObj);
ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
if (HasErrors)
return false;
@@ -303,7 +303,7 @@ namespace AyaNova.Biz
//Log modification and save context
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
SearchIndex(dbObj, false);
SearchIndexAsync(dbObj, false);
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
@@ -333,13 +333,13 @@ namespace AyaNova.Biz
}
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
Validate(dbObj, SnapshotOfOriginalDBObj);
ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
if (HasErrors)
return false;
//Log modification and save context
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
SearchIndex(dbObj, false);
SearchIndexAsync(dbObj, false);
TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
@@ -347,16 +347,16 @@ namespace AyaNova.Biz
}
private void SearchIndex(User obj, bool isNew)
private async Task SearchIndexAsync(User obj, bool isNew)
{
//SEARCH INDEXING
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, obj.Id, BizType, obj.Name);
SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.EmployeeNumber).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
if (isNew)
Search.ProcessNewObjectKeywordsAsync(SearchParams);
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
else
Search.ProcessUpdatedObjectKeywordsAsync(SearchParams);
await Search.ProcessUpdatedObjectKeywordsAsync(SearchParams);
}
@@ -392,7 +392,7 @@ namespace AyaNova.Biz
//
//Can save or update?
private void Validate(User proposedObj, User currentObj)
private async Task ValidateAsync(User proposedObj, User currentObj)
{
//run validation and biz rules
bool isNew = currentObj == null;
@@ -403,7 +403,7 @@ namespace AyaNova.Biz
if (proposedObj.IsTech && proposedObj.Active)
{
//Yes, it might be affected depending on things
long CurrentActiveCount = UserBiz.ActiveCount;
long CurrentActiveCount = await UserBiz.ActiveCountAsync();
long LicensedUserCount = AyaNova.Core.License.ActiveKey.ActiveNumber;
if (isNew)
@@ -440,7 +440,7 @@ namespace AyaNova.Biz
if (!PropertyHasErrors("Name"))
{
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
if (ct.User.Any(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
if (await ct.User.AnyAsync(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
{
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
}
@@ -531,7 +531,7 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "EmployeeNumber", "255 max");
//Any form customizations to validate?
var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == AyaFormFieldDefinitions.USER_KEY);
var FormCustomization = await ct.FormCustom.SingleOrDefaultAsync(x => x.FormKey == AyaFormFieldDefinitions.USER_KEY);
if (FormCustomization != null)
{
//Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required