Пример #1
0
        public IActionResult AddKey(AddKeyViewModel model)
        {
            if (ModelState.IsValid)
            {
                var isValid = model.LocalizedStrings.All(x => !string.IsNullOrEmpty(x.Value));

                if (!isValid)
                {
                    ModelState.AddModelError(string.Empty, "Empty translations");
                }
                else
                if (!_localize[model.NewKey].ResourceNotFound)
                {
                    ModelState.AddModelError(string.Empty, "Key already exists");
                }
                else
                {
                    _localizationService.AddOrUpdateKey(model.NewKey, model.LocalizedStrings);
                    return(RedirectToAction("Index", "Localization", new { page = 1, perPage = 10 }));
                }
            }

            if (model.Languages == null)
            {
                model.Languages = _locConfig.Value.Languages.ToDictionary(f => f.Identifier, f => f.Name);
            }

            return(View(model));
        }