diff --git a/server/AyaNova/Controllers/LicenseController.cs b/server/AyaNova/Controllers/LicenseController.cs
index 9dbfa4da..5d3ed0a7 100644
--- a/server/AyaNova/Controllers/LicenseController.cs
+++ b/server/AyaNova/Controllers/LicenseController.cs
@@ -1,13 +1,16 @@
using System;
+using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
+
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
-using System.ComponentModel.DataAnnotations;
+
+
namespace AyaNova.Api.Controllers
@@ -78,7 +81,7 @@ namespace AyaNova.Api.Controllers
///
/// On success returns information about the currently installed license in AyaNova
[HttpPost]
- public ActionResult FetchLicense()
+ public async Task FetchLicense()
{
//Open or opsOnly and user is opsadminfull
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
@@ -98,7 +101,7 @@ namespace AyaNova.Api.Controllers
try
{
- AyaNova.Core.License.FetchKeyAsync(serverState, ct, log);
+ await AyaNova.Core.License.FetchKeyAsync(serverState, ct, log);
}
catch (Exception ex)
{
@@ -121,8 +124,8 @@ namespace AyaNova.Api.Controllers
}
var ret = AyaNova.Core.License.LicenseInfoAsJson;
//Log
- EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
-
+ await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
+
return Ok(ApiOkResponse.Response(ret, true));
}
@@ -137,12 +140,13 @@ namespace AyaNova.Api.Controllers
///
/// HTTP 204 No Content result code on success or fail code with explanation
[HttpPost("trial")]
- public ActionResult RequestTrial([FromBody] dtoTrialRequestData requestData)
+ public async Task RequestTrial([FromBody] dtoTrialRequestData requestData)
{
//Open or opsOnly and user is opsadminfull
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
+ //return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
if (!Authorized.HasCreateRole(HttpContext.Items, AyaType.License))
@@ -155,7 +159,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
}
- if (!AyaNova.Util.DbUtil.DBIsEmptyAsync(ct, log))
+ if (!await AyaNova.Util.DbUtil.DBIsEmptyAsync(ct, log))
{
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Only an empty AyaNova database can request a trial key. Erase the database to proceed with a new trial."));
}
@@ -166,11 +170,11 @@ namespace AyaNova.Api.Controllers
}
//Send the request to RockFish here (or at least start the job to do it in which case return Accepted instead of no content and update comment above)
- var ret = Core.License.RequestTrialAsync(requestData.EmailAddress, requestData.RegisteredTo, log);
+ var ret = await Core.License.RequestTrialAsync(requestData.EmailAddress, requestData.RegisteredTo, log);
//Log
- EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
-
+ await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
+
return Ok(ApiOkResponse.Response(ret, true));
}
diff --git a/server/AyaNova/Controllers/WidgetController.cs b/server/AyaNova/Controllers/WidgetController.cs
index 0282c9d3..0f2c91dc 100644
--- a/server/AyaNova/Controllers/WidgetController.cs
+++ b/server/AyaNova/Controllers/WidgetController.cs
@@ -1,4 +1,3 @@
-using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -7,7 +6,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
-using Newtonsoft.Json.Linq;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs
index a1af69e4..32efcbc8 100644
--- a/server/AyaNova/biz/UserBiz.cs
+++ b/server/AyaNova/biz/UserBiz.cs
@@ -1,12 +1,10 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
-using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.JsonPatch;
using EnumsNET;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
-using AyaNova.Biz;
using AyaNova.Models;
using Newtonsoft.Json.Linq;
using System;
@@ -36,7 +34,8 @@ namespace AyaNova.Biz
{
var ct = ServiceProviderProvider.DBContext;
var ret = await ct.User.Where(x => x.Active == true && (x.UserType == UserType.Schedulable || x.UserType == UserType.Subcontractor)).LongCountAsync();
- return ret;
+
+ return ret;
}
internal static UserBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs
index 61a4ddec..3f17ee07 100644
--- a/server/AyaNova/util/DbUtil.cs
+++ b/server/AyaNova/util/DbUtil.cs
@@ -5,6 +5,17 @@ using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.AspNetCore.JsonPatch;
+using EnumsNET;
+using AyaNova.Util;
+using AyaNova.Api.ControllerHelpers;
+using AyaNova.Models;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
namespace AyaNova.Util
{
@@ -325,7 +336,7 @@ namespace AyaNova.Util
// Check if DB is empty
// CALLED BY LICENSE CONTROLLER AND LICENSE.CS FOR TRIAL Request check
// Also called by Import
- internal static bool DBIsEmpty(AyContext ct, ILogger _log)
+ internal static async Task DBIsEmptyAsync(AyContext ct, ILogger _log)
{
//TODO: This needs to be way more thorough, only the main tables though, no need to get crazy with it
//just stuff that would be shitty to have to re-enter
@@ -333,7 +344,8 @@ namespace AyaNova.Util
_log.LogDebug("DB empty check");
//An empty db contains only one User
- if (ct.User.Count() > 1) return false;
+ if (await ct.User.LongCountAsync() > 1) return false;
+
//No clients
//if(ctx.Client.Count()>0) return false;
diff --git a/server/AyaNova/util/License.cs b/server/AyaNova/util/License.cs
index ead72903..2b83841a 100644
--- a/server/AyaNova/util/License.cs
+++ b/server/AyaNova/util/License.cs
@@ -11,12 +11,9 @@ using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
//JSON KEY
-using Newtonsoft.Json;
using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.OpenSsl;
-//using System.Security.Cryptography;
-//using Microsoft.AspNetCore.Cryptography.KeyDerivation;
+
@@ -522,7 +519,7 @@ namespace AyaNova.Core
}
//Can't install a trial into a non-empty db
- if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmptyAsync(ct, log))
+ if (ParsedNewKey.TrialLicense && ! DbUtil.DBIsEmptyAsync(ct, log))
{
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
}