This commit is contained in:
@@ -236,53 +236,53 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update WorkOrderState
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="updatedObject">WorkOrderState - top level only, no descendants</param>
|
||||
/// <returns>New concurrency token</returns>
|
||||
[HttpPut("states/")]
|
||||
public async Task<IActionResult> PutWorkOrderState([FromBody] WorkOrderState updatedObject)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.WorkOrderStatus))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
var o = await biz.StatePutAsync(updatedObject);//In future may need to return entire object, for now just concurrency token
|
||||
if (o == null)
|
||||
{
|
||||
if (biz.Errors.Exists(z => z.Code == ApiErrorCode.CONCURRENCY_CONFLICT))
|
||||
return StatusCode(409, new ApiErrorResponse(biz.Errors));
|
||||
else
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Update WorkOrderState
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <param name="updatedObject">WorkOrderState - top level only, no descendants</param>
|
||||
// /// <returns>New concurrency token</returns>
|
||||
// [HttpPut("states/")]
|
||||
// public async Task<IActionResult> PutWorkOrderState([FromBody] WorkOrderState updatedObject)
|
||||
// {
|
||||
// if (!serverState.IsOpen)
|
||||
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
// if (!ModelState.IsValid)
|
||||
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||
// if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.WorkOrderStatus))
|
||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
// var o = await biz.StatePutAsync(updatedObject);//In future may need to return entire object, for now just concurrency token
|
||||
// if (o == null)
|
||||
// {
|
||||
// if (biz.Errors.Exists(z => z.Code == ApiErrorCode.CONCURRENCY_CONFLICT))
|
||||
// return StatusCode(409, new ApiErrorResponse(biz.Errors));
|
||||
// else
|
||||
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
// }
|
||||
// return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||
// }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete WorkOrderState
|
||||
/// </summary>
|
||||
/// <param name="WorkOrderStateId"></param>
|
||||
/// <returns>NoContent</returns>
|
||||
[HttpDelete("states/{WorkOrderStateId}")]
|
||||
public async Task<IActionResult> DeleteWorkOrderState([FromRoute] long WorkOrderStateId)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||
if (!Authorized.HasDeleteRole(HttpContext.Items, AyaType.WorkOrderStatus))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!await biz.StateDeleteAsync(WorkOrderStateId))
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
return NoContent();
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Delete WorkOrderState
|
||||
// /// </summary>
|
||||
// /// <param name="WorkOrderStateId"></param>
|
||||
// /// <returns>NoContent</returns>
|
||||
// [HttpDelete("states/{WorkOrderStateId}")]
|
||||
// public async Task<IActionResult> DeleteWorkOrderState([FromRoute] long WorkOrderStateId)
|
||||
// {
|
||||
// if (!serverState.IsOpen)
|
||||
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
// if (!ModelState.IsValid)
|
||||
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||
// WorkOrderBiz biz = WorkOrderBiz.GetBiz(ct, HttpContext);
|
||||
// if (!Authorized.HasDeleteRole(HttpContext.Items, AyaType.WorkOrderStatus))
|
||||
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
// if (!await biz.StateDeleteAsync(WorkOrderStateId))
|
||||
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
// return NoContent();
|
||||
// }
|
||||
|
||||
#endregion workorderstate
|
||||
|
||||
|
||||
@@ -687,77 +687,77 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//UPDATE
|
||||
//
|
||||
internal async Task<WorkOrderState> StatePutAsync(WorkOrderState putObject)
|
||||
{
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //UPDATE
|
||||
// //
|
||||
// internal async Task<WorkOrderState> StatePutAsync(WorkOrderState putObject)
|
||||
// {
|
||||
|
||||
WorkOrderState dbObject = await StateGetAsync(putObject.Id, false);
|
||||
if (dbObject == null)
|
||||
{
|
||||
AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||
return null;
|
||||
}
|
||||
if (dbObject.Concurrency != putObject.Concurrency)
|
||||
{
|
||||
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||
return null;
|
||||
}
|
||||
await StateValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
ct.Replace(dbObject, putObject);
|
||||
try
|
||||
{
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await ItemExistsAsync(putObject.Id))
|
||||
AddError(ApiErrorCode.NOT_FOUND);
|
||||
else
|
||||
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||
return null;
|
||||
}
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderStatus, AyaEvent.Modified), ct);
|
||||
// WorkOrderState dbObject = await StateGetAsync(putObject.Id, false);
|
||||
// if (dbObject == null)
|
||||
// {
|
||||
// AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||
// return null;
|
||||
// }
|
||||
// if (dbObject.Concurrency != putObject.Concurrency)
|
||||
// {
|
||||
// AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||
// return null;
|
||||
// }
|
||||
// await StateValidateAsync(putObject, dbObject);
|
||||
// if (HasErrors) return null;
|
||||
// ct.Replace(dbObject, putObject);
|
||||
// try
|
||||
// {
|
||||
// await ct.SaveChangesAsync();
|
||||
// }
|
||||
// catch (DbUpdateConcurrencyException)
|
||||
// {
|
||||
// if (!await ItemExistsAsync(putObject.Id))
|
||||
// AddError(ApiErrorCode.NOT_FOUND);
|
||||
// else
|
||||
// AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||
// return null;
|
||||
// }
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderStatus, AyaEvent.Modified), ct);
|
||||
|
||||
await StateHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||
return putObject;
|
||||
}
|
||||
// await StateHandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
|
||||
// return putObject;
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> StateDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction transaction = null;
|
||||
if (parentTransaction == null)
|
||||
transaction = await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
WorkOrderState dbObject = await StateGetAsync(id, false);
|
||||
StateValidateCanDelete(dbObject);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //DELETE
|
||||
// //
|
||||
// internal async Task<bool> StateDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
// {
|
||||
// Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction transaction = null;
|
||||
// if (parentTransaction == null)
|
||||
// transaction = await ct.Database.BeginTransactionAsync();
|
||||
// try
|
||||
// {
|
||||
// WorkOrderState dbObject = await StateGetAsync(id, false);
|
||||
// StateValidateCanDelete(dbObject);
|
||||
// if (HasErrors)
|
||||
// return false;
|
||||
|
||||
ct.WorkOrderState.Remove(dbObject);
|
||||
await ct.SaveChangesAsync();
|
||||
// ct.WorkOrderState.Remove(dbObject);
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
//Log event
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, AyaType.WorkOrderStatus, dbObject.Id, "wo:" + dbObject.WorkOrderId.ToString(), ct);
|
||||
// //Log event
|
||||
// await EventLogProcessor.DeleteObjectLogAsync(UserId, AyaType.WorkOrderStatus, dbObject.Id, "wo:" + dbObject.WorkOrderId.ToString(), ct);
|
||||
|
||||
//all good do the commit if it's ours
|
||||
if (parentTransaction == null)
|
||||
await transaction.CommitAsync();
|
||||
await StateHandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||
throw;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// //all good do the commit if it's ours
|
||||
// if (parentTransaction == null)
|
||||
// await transaction.CommitAsync();
|
||||
// await StateHandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// //Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||
// throw;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -781,21 +781,21 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
private void StateValidateCanDelete(WorkOrderState obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||
return;
|
||||
}
|
||||
// private void StateValidateCanDelete(WorkOrderState obj)
|
||||
// {
|
||||
// if (obj == null)
|
||||
// {
|
||||
// AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||
// return;
|
||||
// }
|
||||
|
||||
//re-check rights here necessary due to traversal delete from Principle object
|
||||
if (!Authorized.HasDeleteRole(CurrentUserRoles, AyaType.WorkOrderStatus))
|
||||
{
|
||||
AddError(ApiErrorCode.NOT_AUTHORIZED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// //re-check rights here necessary due to traversal delete from Principle object
|
||||
// if (!Authorized.HasDeleteRole(CurrentUserRoles, AyaType.WorkOrderStatus))
|
||||
// {
|
||||
// AddError(ApiErrorCode.NOT_AUTHORIZED);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -20,9 +20,7 @@ namespace AyaNova.Models
|
||||
public long UserId { get; set; }
|
||||
|
||||
//UTILITY FIELDS
|
||||
[NotMapped]
|
||||
public bool IsDirty { get; set; } = false;//never dirty coming from the server
|
||||
|
||||
|
||||
//related
|
||||
public WorkOrderStatus WorkOrderStatus { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user