diff --git a/server/AyaNova/Controllers/PartController.cs b/server/AyaNova/Controllers/PartController.cs
index 0d826065..51d27d7d 100644
--- a/server/AyaNova/Controllers/PartController.cs
+++ b/server/AyaNova/Controllers/PartController.cs
@@ -265,7 +265,7 @@ namespace AyaNova.Api.Controllers
///PartId
///
[HttpPut("part-cost/{id}")]
- public async Task PutPartSerials([FromRoute] long id, [FromBody] decimal newCost)
+ public async Task PutPartCost([FromRoute] long id, [FromBody] decimal newCost)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
@@ -274,18 +274,15 @@ namespace AyaNova.Api.Controllers
PartBiz biz = PartBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
-
-
- var o = await biz.PutPartCostAsync(id, newCost);
- if (o == null)
+
+ if (await biz.PutPartCostAsync(id, newCost) == false)
{
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(o));
+ return NoContent();
}
diff --git a/server/AyaNova/biz/PartBiz.cs b/server/AyaNova/biz/PartBiz.cs
index 9ef8db17..8f38809d 100644
--- a/server/AyaNova/biz/PartBiz.cs
+++ b/server/AyaNova/biz/PartBiz.cs
@@ -348,6 +348,37 @@ namespace AyaNova.Biz
return ret;
}
+ ////////////////////////////////////////////////////////////////////////////////////////////////
+ //UPDATE PART COST
+ //
+ internal async Task 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
//