Index()
{
var errorBlock = string.Empty;
if (serverState.IsSystemLocked)
@@ -67,7 +68,7 @@ namespace AyaNova.Api.Controllers
Schema version
{AySchema.currentSchema.ToString()}
Active techs
- {UserBiz.ActiveCount}
+ {await UserBiz.ActiveCountAsync()}
Server time
{DateUtil.ServerDateTimeString(System.DateTime.UtcNow)}
{TimeZoneInfo.Local.Id}
diff --git a/server/AyaNova/Controllers/DataListTemplateController.cs b/server/AyaNova/Controllers/DataListTemplateController.cs
index 7cd27416..bcd69bf3 100644
--- a/server/AyaNova/Controllers/DataListTemplateController.cs
+++ b/server/AyaNova/Controllers/DataListTemplateController.cs
@@ -122,7 +122,7 @@ namespace AyaNova.Api.Controllers
try
{
- if (!biz.PutAsync(o, inObj, DataList))
+ if (!await biz.PutAsync(o, inObj, DataList))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
@@ -168,7 +168,7 @@ namespace AyaNova.Api.Controllers
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
- if (!biz.DeleteAsync(o))
+ if (!await biz.DeleteAsync(o))
return BadRequest(new ApiErrorResponse(biz.Errors));
return NoContent();
diff --git a/server/AyaNova/Controllers/FormCustomController.cs b/server/AyaNova/Controllers/FormCustomController.cs
index a53998be..ac17779b 100644
--- a/server/AyaNova/Controllers/FormCustomController.cs
+++ b/server/AyaNova/Controllers/FormCustomController.cs
@@ -165,7 +165,7 @@ namespace AyaNova.Api.Controllers
try
{
- if (!biz.PutAsync(o, inObj))
+ if (!await biz.PutAsync(o, inObj))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
diff --git a/server/AyaNova/Controllers/LocaleController.cs b/server/AyaNova/Controllers/LocaleController.cs
index 7442ddd9..83eebcf6 100644
--- a/server/AyaNova/Controllers/LocaleController.cs
+++ b/server/AyaNova/Controllers/LocaleController.cs
@@ -231,14 +231,14 @@ namespace AyaNova.Api.Controllers
try
{
- if (!biz.PutLocaleItemDisplayTextAsync(oFromDb, inObj, oDbParent))
+ if (!await biz.PutLocaleItemDisplayTextAsync(oFromDb, inObj, oDbParent))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
}
catch (DbUpdateConcurrencyException)
{
- if (!biz.LocaleItemExistsAsync(inObj.Id))
+ if (!await biz.LocaleItemExistsAsync(inObj.Id))
{
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
}
@@ -293,7 +293,7 @@ namespace AyaNova.Api.Controllers
try
{
- if (!biz.PutLocaleNameAsync(oFromDb, inObj))
+ if (!await biz.PutLocaleNameAsync(oFromDb, inObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
@@ -301,7 +301,7 @@ namespace AyaNova.Api.Controllers
}
catch (DbUpdateConcurrencyException)
{
- if (!biz.LocaleExistsAsync(inObj.Id))
+ if (!await biz.LocaleExistsAsync(inObj.Id))
{
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
}
@@ -340,7 +340,7 @@ namespace AyaNova.Api.Controllers
//Fetch locale and it's children
//(fetch here so can return proper REST responses on failing basic validity)
- var dbObj = ct.Locale.Include(x => x.LocaleItems).SingleOrDefault(m => m.Id == id);
+ var dbObj = await ct.Locale.Include(x => x.LocaleItems).SingleOrDefaultAsync(m => m.Id == id);
if (dbObj == null)
{
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
@@ -353,21 +353,12 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
- //LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
- if (!biz.DeleteAsync(dbObj))
+ if (!await biz.DeleteAsync(dbObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
- //Log
- EventLogProcessor.DeleteObjectLogAsync(biz.UserId, AyaType.Locale, dbObj.Id, dbObj.Name, ct);
- await ct.SaveChangesAsync();
-
- //Delete children / attached objects
- // biz.DeleteChildren(dbObj);
-
-
-
+
return NoContent();
}
diff --git a/server/AyaNova/Controllers/UserController.cs b/server/AyaNova/Controllers/UserController.cs
index 5ca38852..1b553b9f 100644
--- a/server/AyaNova/Controllers/UserController.cs
+++ b/server/AyaNova/Controllers/UserController.cs
@@ -124,7 +124,7 @@ namespace AyaNova.Api.Controllers
try
{
- if (!biz.PutAsync(o, inObj))
+ if (!await 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.PatchAsync(o, objectPatch, concurrencyToken))
+ if (!await biz.PatchAsync(o, objectPatch, concurrencyToken))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
@@ -288,7 +288,7 @@ namespace AyaNova.Api.Controllers
}
- if (!biz.DeleteAsync(dbObj))
+ if (!await biz.DeleteAsync(dbObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
diff --git a/server/AyaNova/Controllers/WidgetController.cs b/server/AyaNova/Controllers/WidgetController.cs
index 296d6174..3bebb228 100644
--- a/server/AyaNova/Controllers/WidgetController.cs
+++ b/server/AyaNova/Controllers/WidgetController.cs
@@ -109,7 +109,7 @@ namespace AyaNova.Api.Controllers
try
{
- if (!biz.PutAsync(o, inObj))
+ if (!await biz.PutAsync(o, inObj))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
@@ -155,7 +155,7 @@ namespace AyaNova.Api.Controllers
try
{
//patch and validate
- if (!biz.PatchAsync(o, objectPatch, concurrencyToken))
+ if (!await biz.PatchAsync(o, objectPatch, concurrencyToken))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
@@ -176,7 +176,7 @@ namespace AyaNova.Api.Controllers
/// Automatically filled from route path, no need to specify in body
///
[HttpPost]
- public IActionResult PostWidget([FromBody] Widget inObj, ApiVersion apiVersion)
+ public async Task PostWidget([FromBody] Widget inObj, ApiVersion apiVersion)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
@@ -192,7 +192,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
//Create and validate
- Widget o = biz.Create(inObj);
+ Widget o = await biz.CreateAsync(inObj);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
@@ -262,7 +262,7 @@ namespace AyaNova.Api.Controllers
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
- if (!biz.DeleteAsync(o))
+ if (!await biz.DeleteAsync(o))
return BadRequest(new ApiErrorResponse(biz.Errors));
return NoContent();
diff --git a/server/AyaNova/biz/LocaleBiz.cs b/server/AyaNova/biz/LocaleBiz.cs
index ee462d3a..e943f4d2 100644
--- a/server/AyaNova/biz/LocaleBiz.cs
+++ b/server/AyaNova/biz/LocaleBiz.cs
@@ -289,6 +289,8 @@ namespace AyaNova.Biz
return false;
ct.Locale.Remove(dbObj);
await ct.SaveChangesAsync();
+ //Log
+ await EventLogProcessor.DeleteObjectLogAsync(UserId, AyaType.Locale, dbObj.Id, dbObj.Name, ct);
return true;
}
diff --git a/server/AyaNova/util/License.cs b/server/AyaNova/util/License.cs
index 347172b6..ae31167a 100644
--- a/server/AyaNova/util/License.cs
+++ b/server/AyaNova/util/License.cs
@@ -417,23 +417,23 @@ namespace AyaNova.Core
/// Initialize the key
/// Handle if first boot scenario to tag DB ID etc
///
- internal static void Initialize(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ctx, ILogger log)
+ internal static async Task Initialize(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log)
{
log.LogDebug("Initializing license");
try
{
//Fetch key from db as no tracking so doesn't hang round if need to immediately clear and then re-add the key
- Models.License ldb = ctx.License.AsNoTracking().SingleOrDefault();
+ Models.License ldb = ct.License.AsNoTracking().SingleOrDefault();
//Non existent license should restrict server to ops routes only with closed API
if (ldb == null)
{
ldb = new Models.License();
- ldb.DbId = Guid.NewGuid();
+ ldb.DbId = Guid.NewGuid();
ldb.Key = "none";
- ctx.License.Add(ldb);
- ctx.SaveChanges();
+ ct.License.Add(ldb);
+ await ct.SaveChangesAsync();
}
//ensure DB ID
@@ -442,8 +442,8 @@ namespace AyaNova.Core
ldb.DbId = Guid.NewGuid();
//Convert the no tracking record fetched above to tracking
//this is required because a prior call to initialize before dumping the db would mean the license is still in memory in the context
- ctx.Entry(ldb).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
- ctx.SaveChanges();
+ ct.Entry(ldb).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
+ await ct.SaveChangesAsync();
}
//Get it early and set it here so that it can be displayed early to the user even if not licensed
@@ -478,7 +478,7 @@ namespace AyaNova.Core
}
//Has someone been trying funny business with the active techs in the db?
- if (AyaNova.Biz.UserBiz.ActiveCount > _ActiveLicense.ActiveNumber)
+ if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > _ActiveLicense.ActiveNumber)
{
var msg = $"E1020 - Active count exceeded capacity";
apiServerState.SetSystemLock(msg);
@@ -508,11 +508,11 @@ namespace AyaNova.Core
///
/// Install key to db
///
- private static bool Install(string RawTextNewKey, AyaNovaLicenseKey ParsedNewKey, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ctx, ILogger log)
+ private static async Task Install(string RawTextNewKey, AyaNovaLicenseKey ParsedNewKey, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log)
{
try
{
- var CurrentInDbKeyRecord = ctx.License.OrderBy(x => x.Id).FirstOrDefault();
+ var CurrentInDbKeyRecord = await ct.License.OrderBy(x => x.Id).FirstOrDefaultAsync();
if (CurrentInDbKeyRecord == null)
throw new ApplicationException("E1020 - Can't install key, no key record found");
@@ -522,13 +522,13 @@ namespace AyaNova.Core
}
//Can't install a trial into a non-empty db
- if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmpty(ctx, log))
+ if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmpty(ct, log))
{
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
}
//TODO: TECHCOUNT - new license causes exceeding count?
- if (AyaNova.Biz.UserBiz.ActiveCount > ParsedNewKey.GetLicenseFeature(SERVICE_TECHS_FEATURE_NAME).Count)
+ if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > ParsedNewKey.GetLicenseFeature(SERVICE_TECHS_FEATURE_NAME).Count)
{
throw new ApplicationException("E1020 - Can't install key, too many active techs and / or subcontractors in database. Deactivate enough to install key.");
}
@@ -537,7 +537,7 @@ namespace AyaNova.Core
CurrentInDbKeyRecord.Key = RawTextNewKey;
//LOOKAT: reason, resultcode etc
//There is similar block related to this in ayschema for db schema version 8
- ctx.SaveChanges();
+ ct.SaveChanges();
}
catch (Exception ex)
{
@@ -547,7 +547,7 @@ namespace AyaNova.Core
}
finally
{
- Initialize(apiServerState, ctx, log);
+ await Initialize(apiServerState, ct, log);
}
return true;
}