This commit is contained in:
@@ -237,6 +237,67 @@ namespace AyaNova.Api.Controllers
|
||||
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = oFromDb.ConcurrencyToken }, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Put (UpdateTranslationItemDisplayText)
|
||||
/// Update a list of items with new display text
|
||||
/// </summary>
|
||||
/// <param name="inObj">Array of NewText/Id/Concurrency token objects. NewText is new display text, Id is TranslationItem Id, concurrency token is required</param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("UpdateTranslationItemsDisplayText")]
|
||||
public async Task<IActionResult> PutTranslationItemsDisplayText([FromBody] List<NewTextIdConcurrencyTokenItem> inObj)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
var oFromDb = await ct.TranslationItem.AsNoTracking().SingleOrDefaultAsync(m => m.Id == inObj[0].Id);
|
||||
|
||||
if (oFromDb == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
//Now fetch translation for rights and to ensure not stock
|
||||
var oDbParent = await ct.Translation.SingleOrDefaultAsync(x => x.Id == oFromDb.TranslationId);
|
||||
if (oDbParent == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.Translation))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
try
|
||||
{
|
||||
if (!await biz.PutTranslationItemsDisplayTextAsync(inObj, oDbParent))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
|
||||
//exists but was changed by another user
|
||||
//I considered returning new and old record, but where would it end?
|
||||
//Better to let the client decide what to do than to send extra data that is not required
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Put (UpdateTranslationName)
|
||||
/// Update a translation to change the name (non-stock Translations only)
|
||||
|
||||
Reference in New Issue
Block a user