Added "move" action for dictionaries (#12193)

* Added "move" action for dictionaries

* Replaced DictionaryMove with MoveOrCopy for PostMove

* Removed int parse for dictionary postmove id & parentId, changed paramtype for move in dictionary.resource

* Added localizedText for new dictionary validationProblems &  adjusted nullcheck for move.ParentId

* Fixed logic for move dictionary parent
This commit is contained in:
Johannes Lantz
2022-04-04 17:14:03 +02:00
committed by GitHub
parent 534ca928b4
commit 057b304a5a
7 changed files with 206 additions and 1 deletions

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
@@ -191,6 +193,39 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
return _umbracoMapper.Map<IDictionaryItem, DictionaryDisplay>(dictionary);
}
/// <summary>
/// Changes the structure for dictionary items
/// </summary>
/// <param name="move"></param>
/// <returns></returns>
public IActionResult PostMove(MoveOrCopy move)
{
var dictionaryItem = _localizationService.GetDictionaryItemById(move.Id);
if (dictionaryItem == null)
return ValidationProblem(_localizedTextService.Localize("dictionary", "itemDoesNotExists"));
var parent = _localizationService.GetDictionaryItemById(move.ParentId);
if (parent == null)
{
if (move.ParentId == Constants.System.Root)
dictionaryItem.ParentId = null;
else
return ValidationProblem(_localizedTextService.Localize("dictionary", "parentDoesNotExists"));
}
else
{
dictionaryItem.ParentId = parent.Key;
if (dictionaryItem.Key == parent.ParentId)
return ValidationProblem(_localizedTextService.Localize("moveOrCopy", "notAllowedByPath"));
}
_localizationService.Save(dictionaryItem);
var model = _umbracoMapper.Map<IDictionaryItem, DictionaryDisplay>(dictionaryItem);
return Content(model.Path, MediaTypeNames.Text.Plain, Encoding.UTF8);
}
/// <summary>
/// Saves a dictionary item
/// </summary>