This commit is contained in:
2020-11-25 18:43:52 +00:00
parent fcab7cb1ae
commit f7cb5ac0c3
2 changed files with 190 additions and 4 deletions

View File

@@ -401,18 +401,133 @@ namespace AyaNova.Api.Controllers
}
// private static void DeleteTempUploadFile(ApiUploadProcessor.ApiUploadedFilesResult uploadFormData)
// /// <summary>
// /// Put (UpdateTranslationItemDisplayText)
// /// Update a single key with new display text
// /// </summary>
// /// <param name="inObj">NewText/Id/Concurrency token object. NewText is new display text, Id is TranslationItem Id, concurrency token is required</param>
// /// <returns></returns>
// [HttpPut("updatetranslationitemdisplaytext")]
// public async Task<IActionResult> PutTranslationItemDisplayText([FromBody] NewTextIdConcurrencyTokenItem inObj)
// {
// if (uploadFormData.UploadedFiles.Count > 0)
// if (serverState.IsClosed)
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
// if (!ModelState.IsValid)
// {
// foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
// return BadRequest(new ApiErrorResponse(ModelState));
// }
// var oFromDb = await ct.TranslationItem.SingleOrDefaultAsync(z => z.Id == inObj.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(z => z.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.PutTranslationItemDisplayTextAsync(oFromDb, inObj, oDbParent))
// {
// System.IO.File.Delete(a.InitialUploadedPathName);
// return BadRequest(new ApiErrorResponse(biz.Errors));
// }
// }
// catch (DbUpdateConcurrencyException)
// {
// if (!await biz.TranslationItemExistsAsync(inObj.Id))
// {
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
// }
// else
// {
// //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 Ok(ApiOkResponse.Response(new { Concurrency = oFromDb.Concurrency }));
// }
/// <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(z => z.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(z => z.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();
}
#if (DEBUG)
public class TranslationCoverageInfo
{