This commit is contained in:
@@ -5,6 +5,7 @@ using AyaNova.Util;
|
|||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
{
|
{
|
||||||
@@ -36,7 +37,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ContentResult Index()
|
public async Task<ContentResult> Index()
|
||||||
{
|
{
|
||||||
var errorBlock = string.Empty;
|
var errorBlock = string.Empty;
|
||||||
if (serverState.IsSystemLocked)
|
if (serverState.IsSystemLocked)
|
||||||
@@ -67,7 +68,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
<h4>Schema version</h4>
|
<h4>Schema version</h4>
|
||||||
<pre>{AySchema.currentSchema.ToString()}</pre>
|
<pre>{AySchema.currentSchema.ToString()}</pre>
|
||||||
<h4>Active techs</h4>
|
<h4>Active techs</h4>
|
||||||
<pre>{UserBiz.ActiveCount}</pre>
|
<pre>{await UserBiz.ActiveCountAsync()}</pre>
|
||||||
<h4>Server time</h4>
|
<h4>Server time</h4>
|
||||||
<pre>{DateUtil.ServerDateTimeString(System.DateTime.UtcNow)}</pre>
|
<pre>{DateUtil.ServerDateTimeString(System.DateTime.UtcNow)}</pre>
|
||||||
<pre>{TimeZoneInfo.Local.Id}</pre>
|
<pre>{TimeZoneInfo.Local.Id}</pre>
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.PutAsync(o, inObj, DataList))
|
if (!await biz.PutAsync(o, inObj, DataList))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
@@ -168,7 +168,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.DeleteAsync(o))
|
if (!await biz.DeleteAsync(o))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.PutAsync(o, inObj))
|
if (!await biz.PutAsync(o, inObj))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
|
|||||||
@@ -231,14 +231,14 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.PutLocaleItemDisplayTextAsync(oFromDb, inObj, oDbParent))
|
if (!await biz.PutLocaleItemDisplayTextAsync(oFromDb, inObj, oDbParent))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if (!biz.LocaleItemExistsAsync(inObj.Id))
|
if (!await biz.LocaleItemExistsAsync(inObj.Id))
|
||||||
{
|
{
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
}
|
}
|
||||||
@@ -293,7 +293,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.PutLocaleNameAsync(oFromDb, inObj))
|
if (!await biz.PutLocaleNameAsync(oFromDb, inObj))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if (!biz.LocaleExistsAsync(inObj.Id))
|
if (!await biz.LocaleExistsAsync(inObj.Id))
|
||||||
{
|
{
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
}
|
}
|
||||||
@@ -340,7 +340,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
//Fetch locale and it's children
|
//Fetch locale and it's children
|
||||||
//(fetch here so can return proper REST responses on failing basic validity)
|
//(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)
|
if (dbObj == null)
|
||||||
{
|
{
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
@@ -353,21 +353,12 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
//LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
|
||||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||||
if (!biz.DeleteAsync(dbObj))
|
if (!await biz.DeleteAsync(dbObj))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
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();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.PutAsync(o, inObj))
|
if (!await biz.PutAsync(o, inObj))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
@@ -183,7 +183,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//patch and validate
|
//patch and validate
|
||||||
if (!biz.PatchAsync(o, objectPatch, concurrencyToken))
|
if (!await biz.PatchAsync(o, objectPatch, concurrencyToken))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
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));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!biz.PutAsync(o, inObj))
|
if (!await 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.PatchAsync(o, objectPatch, concurrencyToken))
|
if (!await biz.PatchAsync(o, objectPatch, concurrencyToken))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
@@ -176,7 +176,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult PostWidget([FromBody] Widget inObj, ApiVersion apiVersion)
|
public async Task<IActionResult> PostWidget([FromBody] Widget inObj, ApiVersion apiVersion)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
@@ -192,7 +192,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
//Create and validate
|
//Create and validate
|
||||||
Widget o = biz.Create(inObj);
|
Widget o = await biz.CreateAsync(inObj);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
else
|
||||||
@@ -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.DeleteAsync(o))
|
if (!await biz.DeleteAsync(o))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|||||||
@@ -289,6 +289,8 @@ namespace AyaNova.Biz
|
|||||||
return false;
|
return false;
|
||||||
ct.Locale.Remove(dbObj);
|
ct.Locale.Remove(dbObj);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
//Log
|
||||||
|
await EventLogProcessor.DeleteObjectLogAsync(UserId, AyaType.Locale, dbObj.Id, dbObj.Name, ct);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -417,23 +417,23 @@ namespace AyaNova.Core
|
|||||||
/// Initialize the key
|
/// Initialize the key
|
||||||
/// Handle if first boot scenario to tag DB ID etc
|
/// Handle if first boot scenario to tag DB ID etc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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");
|
log.LogDebug("Initializing license");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Fetch key from db as no tracking so doesn't hang round if need to immediately clear and then re-add the key
|
//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
|
//Non existent license should restrict server to ops routes only with closed API
|
||||||
if (ldb == null)
|
if (ldb == null)
|
||||||
{
|
{
|
||||||
ldb = new Models.License();
|
ldb = new Models.License();
|
||||||
ldb.DbId = Guid.NewGuid();
|
ldb.DbId = Guid.NewGuid();
|
||||||
ldb.Key = "none";
|
ldb.Key = "none";
|
||||||
ctx.License.Add(ldb);
|
ct.License.Add(ldb);
|
||||||
ctx.SaveChanges();
|
await ct.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
//ensure DB ID
|
//ensure DB ID
|
||||||
@@ -442,8 +442,8 @@ namespace AyaNova.Core
|
|||||||
ldb.DbId = Guid.NewGuid();
|
ldb.DbId = Guid.NewGuid();
|
||||||
//Convert the no tracking record fetched above to tracking
|
//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
|
//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;
|
ct.Entry(ldb).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
ctx.SaveChanges();
|
await ct.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get it early and set it here so that it can be displayed early to the user even if not licensed
|
//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?
|
//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";
|
var msg = $"E1020 - Active count exceeded capacity";
|
||||||
apiServerState.SetSystemLock(msg);
|
apiServerState.SetSystemLock(msg);
|
||||||
@@ -508,11 +508,11 @@ namespace AyaNova.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Install key to db
|
/// Install key to db
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static bool Install(string RawTextNewKey, AyaNovaLicenseKey ParsedNewKey, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ctx, ILogger log)
|
private static async Task<bool> Install(string RawTextNewKey, AyaNovaLicenseKey ParsedNewKey, AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var CurrentInDbKeyRecord = ctx.License.OrderBy(x => x.Id).FirstOrDefault();
|
var CurrentInDbKeyRecord = await ct.License.OrderBy(x => x.Id).FirstOrDefaultAsync();
|
||||||
if (CurrentInDbKeyRecord == null)
|
if (CurrentInDbKeyRecord == null)
|
||||||
throw new ApplicationException("E1020 - Can't install key, no key record found");
|
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
|
//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.");
|
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?
|
//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.");
|
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;
|
CurrentInDbKeyRecord.Key = RawTextNewKey;
|
||||||
//LOOKAT: reason, resultcode etc
|
//LOOKAT: reason, resultcode etc
|
||||||
//There is similar block related to this in ayschema for db schema version 8
|
//There is similar block related to this in ayschema for db schema version 8
|
||||||
ctx.SaveChanges();
|
ct.SaveChanges();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -547,7 +547,7 @@ namespace AyaNova.Core
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Initialize(apiServerState, ctx, log);
|
await Initialize(apiServerState, ct, log);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user