This commit is contained in:
2018-09-26 17:33:07 +00:00
parent ad6b2fc208
commit 1f6695079f
3 changed files with 57 additions and 72 deletions

View File

@@ -73,8 +73,8 @@ namespace AyaNova.Api.Controllers
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
var o = await biz.GetAsync(id);
if (o == null)
@@ -118,7 +118,7 @@ namespace AyaNova.Api.Controllers
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
ApiPagedResponse<System.Object> pr = await biz.GetManyAsync(Url, nameof(ListUsers), pagingOptions);
return Ok(new ApiOkWithPagingResponse<System.Object>(pr));
@@ -154,7 +154,7 @@ namespace AyaNova.Api.Controllers
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
ApiPagedResponse<NameIdItem> pr = await biz.GetPickListAsync(Url, nameof(UserPickList), pagingOptions, q);
return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
}
@@ -196,19 +196,12 @@ namespace AyaNova.Api.Controllers
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
if (!biz.Put(o, inObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
try
{
//Log
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, AyaType.User, AyaEvent.Modified), ct);
await ct.SaveChangesAsync();
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.User, o.Name, o.EmployeeNumber, o.Notes, o.Name);
if (!biz.Put(o, inObj))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
{
@@ -225,8 +218,6 @@ namespace AyaNova.Api.Controllers
}
}
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
}
@@ -257,7 +248,7 @@ namespace AyaNova.Api.Controllers
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
var o = await ct.User.SingleOrDefaultAsync(m => m.Id == id);
@@ -271,18 +262,13 @@ 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.AddEntry(new Event(biz.UserId, o.Id, AyaType.User, AyaEvent.Modified), ct);
await ct.SaveChangesAsync();
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.User, o.Name, o.EmployeeNumber, o.Notes, o.Name);
//patch and validate
if (!biz.Patch(o, objectPatch, concurrencyToken))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
}
catch (DbUpdateConcurrencyException)
{
@@ -296,9 +282,6 @@ namespace AyaNova.Api.Controllers
}
}
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
}
@@ -332,7 +315,7 @@ namespace AyaNova.Api.Controllers
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
//Create and validate
User o = await biz.CreateAsync(inObj);
@@ -345,10 +328,6 @@ namespace AyaNova.Api.Controllers
else
{
//EVENT LOG
//Note that event log is processed in the biz object unlike the widget for no apparent reason
//return success and link
//NOTE: this is a USER object so we don't want to return some key fields for security reasons
//which is why the object is "cleaned" before return
@@ -393,23 +372,12 @@ namespace AyaNova.Api.Controllers
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
if (!biz.Delete(dbObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
//Log
EventLogProcessor.DeleteObject(biz.UserId, AyaType.User, dbObj.Id, dbObj.Name, ct);
await ct.SaveChangesAsync();
//Delete children / attached objects
biz.DeleteChildren(dbObj);
//This will directly execute and is not part of context for saving purposes
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.User);
return NoContent();
}