This commit is contained in:
2020-01-27 21:32:32 +00:00
parent 1f1d1fbabc
commit 693ddb6b4b
8 changed files with 37 additions and 43 deletions

View File

@@ -5,6 +5,7 @@ using AyaNova.Util;
using AyaNova.Biz;
using AyaNova.Api.ControllerHelpers;
using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;
namespace AyaNova.Api.Controllers
{
@@ -36,7 +37,7 @@ namespace AyaNova.Api.Controllers
/// </summary>
/// <returns></returns>
[HttpGet]
public ContentResult Index()
public async Task<ContentResult> Index()
{
var errorBlock = string.Empty;
if (serverState.IsSystemLocked)
@@ -67,7 +68,7 @@ namespace AyaNova.Api.Controllers
<h4>Schema version</h4>
<pre>{AySchema.currentSchema.ToString()}</pre>
<h4>Active techs</h4>
<pre>{UserBiz.ActiveCount}</pre>
<pre>{await UserBiz.ActiveCountAsync()}</pre>
<h4>Server time</h4>
<pre>{DateUtil.ServerDateTimeString(System.DateTime.UtcNow)}</pre>
<pre>{TimeZoneInfo.Local.Id}</pre>

View File

@@ -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();

View File

@@ -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)

View File

@@ -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();
}

View File

@@ -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));
}

View File

@@ -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
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
/// <returns></returns>
[HttpPost]
public IActionResult PostWidget([FromBody] Widget inObj, ApiVersion apiVersion)
public async Task<IActionResult> 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();