This commit is contained in:
@@ -265,7 +265,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
///<param name="id">PartId</param>
|
///<param name="id">PartId</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut("part-cost/{id}")]
|
[HttpPut("part-cost/{id}")]
|
||||||
public async Task<IActionResult> PutPartSerials([FromRoute] long id, [FromBody] decimal newCost)
|
public async Task<IActionResult> PutPartCost([FromRoute] long id, [FromBody] decimal newCost)
|
||||||
{
|
{
|
||||||
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));
|
||||||
@@ -274,18 +274,15 @@ namespace AyaNova.Api.Controllers
|
|||||||
PartBiz biz = PartBiz.GetBiz(ct, HttpContext);
|
PartBiz biz = PartBiz.GetBiz(ct, HttpContext);
|
||||||
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
|
if (await biz.PutPartCostAsync(id, newCost) == false)
|
||||||
var o = await biz.PutPartCostAsync(id, newCost);
|
|
||||||
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 NoContent();
|
||||||
return Ok(ApiOkResponse.Response(o));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -348,6 +348,37 @@ namespace AyaNova.Biz
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//UPDATE PART COST
|
||||||
|
//
|
||||||
|
internal async Task<bool> PutPartCostAsync(long id, decimal newCost)
|
||||||
|
{
|
||||||
|
var dbObject = await ct.Part.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
if (dbObject == null)
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, "id");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
dbObject.Cost = newCost;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if (!await ExistsAsync(id))
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND);
|
||||||
|
else
|
||||||
|
AddError(ApiErrorCode.CONCURRENCY_CONFLICT);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//SEARCH
|
//SEARCH
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user