This commit is contained in:
2018-10-08 18:20:10 +00:00
parent f6c9280a11
commit 40dc278310
15 changed files with 96 additions and 119 deletions

View File

@@ -81,14 +81,14 @@ namespace AyaNova.Api.Controllers
if (o == null)
{
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
}
}
return Ok(new ApiOkResponse(o));
}
/// <summary>
/// Put (update) UserOptions
///
@@ -111,7 +111,7 @@ namespace AyaNova.Api.Controllers
{
return BadRequest(new ApiErrorResponse(ModelState));
}
var UserId = UserIdFromContext.Id(HttpContext.Items);
var UserId = UserIdFromContext.Id(HttpContext.Items);
var o = await ct.UserOptions.SingleOrDefaultAsync(m => m.UserId == id);
@@ -128,16 +128,12 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
UserOptionsBiz biz = new UserOptionsBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
if (!biz.Put(o, inObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
try
{
//Log
EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, o.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
await ct.SaveChangesAsync();
if (!biz.Put(o, inObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
}
catch (DbUpdateConcurrencyException)
{
@@ -169,7 +165,7 @@ namespace AyaNova.Api.Controllers
/// <returns></returns>
[HttpPatch("{id}/{concurrencyToken}")]
public async Task<IActionResult> PatchUserOptions([FromRoute] long id, [FromRoute] uint concurrencyToken, [FromBody]JsonPatchDocument<UserOptions> objectPatch)
{
{
if (!serverState.IsOpen)
{
@@ -181,7 +177,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
}
var UserId = UserIdFromContext.Id(HttpContext.Items);
var UserId = UserIdFromContext.Id(HttpContext.Items);
//Instantiate the business object handler
UserOptionsBiz biz = new UserOptionsBiz(ct, UserId, UserRolesFromContext.Roles(HttpContext.Items));
@@ -198,17 +194,14 @@ namespace AyaNova.Api.Controllers
return StatusCode(401, new ApiNotAuthorizedResponse());
}
//patch and validate
if (!biz.Patch(o, objectPatch, concurrencyToken))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
try
{
//Log
EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, o.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
await ct.SaveChangesAsync();
//patch and validate
if (!biz.Patch(o, objectPatch, concurrencyToken))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
}
catch (DbUpdateConcurrencyException)
{