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