This commit is contained in:
@@ -237,6 +237,67 @@ namespace AyaNova.Api.Controllers
|
|||||||
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = oFromDb.ConcurrencyToken }, true));
|
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>
|
/// <summary>
|
||||||
/// Put (UpdateTranslationName)
|
/// Put (UpdateTranslationName)
|
||||||
/// Update a translation to change the name (non-stock Translations only)
|
/// Update a translation to change the name (non-stock Translations only)
|
||||||
|
|||||||
@@ -242,6 +242,44 @@ namespace AyaNova.Biz
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal async Task<bool> PutTranslationItemsDisplayTextAsync(List<NewTextIdConcurrencyTokenItem> inObj, Translation dbParent)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (dbParent.Stock == true)
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.INVALID_OPERATION, "object", "TranslationItem is from a Stock translation and cannot be modified");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (NewTextIdConcurrencyTokenItem tit in inObj)
|
||||||
|
{
|
||||||
|
var titem=await ct.TranslationItem.SingleOrDefaultAsync(m => m.Id == tit.Id);
|
||||||
|
if(titem==null){
|
||||||
|
AddError(ApiErrorCode.NOT_FOUND, $"Translation item ID {tit.Id}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//Replace the db object with the PUT object
|
||||||
|
//CopyObject.Copy(inObj, dbObj, "Id");
|
||||||
|
titem.Display = tit.NewText;
|
||||||
|
|
||||||
|
//Set "original" value of concurrency token to input token
|
||||||
|
//this will allow EF to check it out
|
||||||
|
ct.Entry(titem).OriginalValues["ConcurrencyToken"] = tit.ConcurrencyToken;
|
||||||
|
|
||||||
|
//Only thing to validate is if it has data at all in it
|
||||||
|
if (string.IsNullOrWhiteSpace(tit.NewText))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, $"Display (NewText) for Id: {tit.Id}");
|
||||||
|
}
|
||||||
|
if (HasErrors)
|
||||||
|
return false;
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
|
//Log
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbParent.Id, AyaType.Translation, AyaEvent.Modified), ct);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal async Task<bool> PutTranslationNameAsync(Translation dbObj, NewTextIdConcurrencyTokenItem inObj)
|
internal async Task<bool> PutTranslationNameAsync(Translation dbObj, NewTextIdConcurrencyTokenItem inObj)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1011,7 +1011,6 @@
|
|||||||
"RecordHistoryModified": "Änderungsdatum dieses Datensatzes",
|
"RecordHistoryModified": "Änderungsdatum dieses Datensatzes",
|
||||||
"RecordHistoryModifier": "Datensatz wurde zuletzt geändert von",
|
"RecordHistoryModifier": "Datensatz wurde zuletzt geändert von",
|
||||||
"AddRemoveButtons": "Schaltflächen hinzufügen und entfernen ...",
|
"AddRemoveButtons": "Schaltflächen hinzufügen und entfernen ...",
|
||||||
"ClientsToolBar": "Kundensymbolleiste",
|
|
||||||
"Customize": "Anpassen ...",
|
"Customize": "Anpassen ...",
|
||||||
"CustomizeDialog_AlwaysShowFullMenus": "Immer vollständige Menüs anzeigen",
|
"CustomizeDialog_AlwaysShowFullMenus": "Immer vollständige Menüs anzeigen",
|
||||||
"CustomizeDialog_CloseNoAmp": "Schließen",
|
"CustomizeDialog_CloseNoAmp": "Schließen",
|
||||||
|
|||||||
@@ -1011,7 +1011,6 @@
|
|||||||
"RecordHistoryModified": "Date this record was last modified",
|
"RecordHistoryModified": "Date this record was last modified",
|
||||||
"RecordHistoryModifier": "Last modifier of this record",
|
"RecordHistoryModifier": "Last modifier of this record",
|
||||||
"AddRemoveButtons": "Add and Remove Buttons....",
|
"AddRemoveButtons": "Add and Remove Buttons....",
|
||||||
"ClientsToolBar": "Clients ToolBar",
|
|
||||||
"Customize": "Customize....",
|
"Customize": "Customize....",
|
||||||
"CustomizeDialog_AlwaysShowFullMenus": "Always show full menus",
|
"CustomizeDialog_AlwaysShowFullMenus": "Always show full menus",
|
||||||
"CustomizeDialog_CloseNoAmp": "Close",
|
"CustomizeDialog_CloseNoAmp": "Close",
|
||||||
|
|||||||
@@ -1011,7 +1011,6 @@
|
|||||||
"RecordHistoryModified": "Fecha de modificación del registro",
|
"RecordHistoryModified": "Fecha de modificación del registro",
|
||||||
"RecordHistoryModifier": "Última modificación de este registro",
|
"RecordHistoryModifier": "Última modificación de este registro",
|
||||||
"AddRemoveButtons": "Añadir y eliminar botones....",
|
"AddRemoveButtons": "Añadir y eliminar botones....",
|
||||||
"ClientsToolBar": "Barra de herramientas Clientes",
|
|
||||||
"Customize": "Personalizar....",
|
"Customize": "Personalizar....",
|
||||||
"CustomizeDialog_AlwaysShowFullMenus": "Mostrar siempre menús completos",
|
"CustomizeDialog_AlwaysShowFullMenus": "Mostrar siempre menús completos",
|
||||||
"CustomizeDialog_CloseNoAmp": "Cerrar",
|
"CustomizeDialog_CloseNoAmp": "Cerrar",
|
||||||
|
|||||||
@@ -1011,7 +1011,6 @@
|
|||||||
"RecordHistoryModified": "Date de la dernière modification de cet enregistrement",
|
"RecordHistoryModified": "Date de la dernière modification de cet enregistrement",
|
||||||
"RecordHistoryModifier": "Dernier utilisateur ayant modifié cet enregistrement",
|
"RecordHistoryModifier": "Dernier utilisateur ayant modifié cet enregistrement",
|
||||||
"AddRemoveButtons": "Ajouter et supprimer des boutons....",
|
"AddRemoveButtons": "Ajouter et supprimer des boutons....",
|
||||||
"ClientsToolBar": "Barre d'outils Clients",
|
|
||||||
"Customize": "Personnaliser....",
|
"Customize": "Personnaliser....",
|
||||||
"CustomizeDialog_AlwaysShowFullMenus": "Toujours afficher les menus complets",
|
"CustomizeDialog_AlwaysShowFullMenus": "Toujours afficher les menus complets",
|
||||||
"CustomizeDialog_CloseNoAmp": "Fermer",
|
"CustomizeDialog_CloseNoAmp": "Fermer",
|
||||||
|
|||||||
Reference in New Issue
Block a user