diff --git a/server/AyaNova/Controllers/ImportAyaNova7Controller.cs b/server/AyaNova/Controllers/ImportAyaNova7Controller.cs index e86fb6b5..4588283f 100644 --- a/server/AyaNova/Controllers/ImportAyaNova7Controller.cs +++ b/server/AyaNova/Controllers/ImportAyaNova7Controller.cs @@ -211,7 +211,7 @@ namespace AyaNova.Api.Controllers /// /// Ok [HttpPost("EraseDatabaseAndStartImport/{filename}")] - public ActionResult EraseDatabaseAndStartImport([FromRoute] string filename) + public async Task EraseDatabaseAndStartImport([FromRoute] string filename) { //Open or opsOnly and user is opsadminfull if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull))) @@ -259,7 +259,7 @@ namespace AyaNova.Api.Controllers j.JobType = JobType.ImportV7Data; //j.O wnerId = UserIdFromContext.Id(HttpContext.Items); j.JobInfo = jobInfo.ToString(); - JobsBiz.AddJobAsync(j, ct); + await JobsBiz.AddJobAsync(j, ct); return Accepted(new { JobId = j.GId });//202 accepted } diff --git a/server/AyaNova/Controllers/UserOptionsController.cs b/server/AyaNova/Controllers/UserOptionsController.cs index f7c84778..65a1c0aa 100644 --- a/server/AyaNova/Controllers/UserOptionsController.cs +++ b/server/AyaNova/Controllers/UserOptionsController.cs @@ -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)); } @@ -189,7 +189,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)); } diff --git a/server/AyaNova/biz/PrimeData.cs b/server/AyaNova/biz/PrimeData.cs index 7af3e8c0..1e11d00c 100644 --- a/server/AyaNova/biz/PrimeData.cs +++ b/server/AyaNova/biz/PrimeData.cs @@ -16,7 +16,7 @@ namespace AyaNova.Biz /// /// Prime the database with manager account /// - public static void PrimeManagerAccount(AyContext ct) + public static async Task PrimeManagerAccount(AyContext ct) { //get a db and logger //ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData"); @@ -31,8 +31,8 @@ namespace AyaNova.Biz u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first u.UserType = UserType.Administrator; u.UserOptions = new UserOptions(); - ct.User.Add(u); - ct.SaveChanges(); + await ct.User.AddAsync(u); + await ct.SaveChangesAsync(); } diff --git a/server/AyaNova/biz/TrialBiz.cs b/server/AyaNova/biz/TrialBiz.cs index 60e24391..0d4c2197 100644 --- a/server/AyaNova/biz/TrialBiz.cs +++ b/server/AyaNova/biz/TrialBiz.cs @@ -64,18 +64,16 @@ namespace AyaNova.Biz //FOR NOW NOT ASYNC so faking it at end of this method - JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct); - JobsBiz.LogJobAsync(job.GId, $"Starting...", ct); + await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct); + await JobsBiz.LogJobAsync(job.GId, $"Starting...", ct); //Get the import filename from the jsondata JObject jobData = JObject.Parse(job.JobInfo); var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value(); var timeZoneOffset = jobData["timeZoneOffset"].Value(); Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset); - JobsBiz.LogJobAsync(job.GId, "Finished.", ct); - JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct); - //NO, BAD! Convert the logjob etc above to async - //await Task.CompletedTask; + await JobsBiz.LogJobAsync(job.GId, "Finished.", ct); + await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct); } diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 32efcbc8..6511189b 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -809,7 +809,7 @@ namespace AyaNova.Biz if (HasErrors) { //If there are any validation errors, log in joblog and move on - JobsBiz.LogJobAsync(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct); + await JobsBiz.LogJobAsync(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct); //This is a fundamental problem with the import as users are required for many things so bomb out entirely //other things might be able to work around but this is too serious @@ -907,8 +907,7 @@ namespace AyaNova.Biz break; } - //just to hide compiler warning for now - await Task.CompletedTask; + //this is the equivalent of returning void for a Task signature with nothing to return return true; diff --git a/server/AyaNova/biz/UserOptionsBiz.cs b/server/AyaNova/biz/UserOptionsBiz.cs index 5fdd1dc5..054d3c27 100644 --- a/server/AyaNova/biz/UserOptionsBiz.cs +++ b/server/AyaNova/biz/UserOptionsBiz.cs @@ -43,10 +43,10 @@ namespace AyaNova.Biz // //put - internal bool Put(UserOptions dbObj, UserOptions inObj) + internal async Task PutAsync(UserOptions dbObj, UserOptions inObj) { - - + + //Replace the db object with the PUT object CopyObject.Copy(inObj, dbObj, "Id, UserId"); //Set "original" value of concurrency token to input token @@ -57,14 +57,14 @@ namespace AyaNova.Biz if (HasErrors) return false; - ct.SaveChanges(); + await ct.SaveChangesAsync(); //Log - EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct); + await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct); return true; } //patch - internal bool Patch(UserOptions dbObj, JsonPatchDocument objectPatch, uint concurrencyToken) + internal async Task PatchAsync(UserOptions dbObj, JsonPatchDocument objectPatch, uint concurrencyToken) { //Validate Patch is allowed if (!ValidateJsonPatch.Validate(this, objectPatch, "UserId")) return false; @@ -77,9 +77,9 @@ namespace AyaNova.Biz if (HasErrors) return false; - ct.SaveChanges(); + await ct.SaveChangesAsync(); //Log - EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct); + await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct); return true; } diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index bfbaa33d..03a4b15a 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -212,7 +212,7 @@ namespace AyaNova.Biz //Determine if the object can be deleted, do the deletion tentatively //Probably also in here deal with tags and associated search text etc - //NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj); + //NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj); if (HasErrors) return false; ct.Widget.Remove(dbObj); @@ -290,7 +290,7 @@ namespace AyaNova.Biz //validate custom fields CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields); } - + } @@ -329,13 +329,13 @@ namespace AyaNova.Biz { var sleepTime = 30 * 1000; //Simulate a long running job here - JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct); - JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct); + await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct); + await JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct); //Uncomment this to test if the job prevents other routes from running //result is NO it doesn't prevent other requests, so we are a-ok for now await Task.Delay(sleepTime); - JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct); - JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct); + await JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct); + await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct); }