Ejemplo n.º 1
0
        public virtual IActionResult ResourceUpdate(LocaleResourceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.ResourceName != null)
            {
                model.ResourceName = model.ResourceName.Trim();
            }
            if (model.ResourceValue != null)
            {
                model.ResourceValue = model.ResourceValue.Trim();
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var resource = _localizationService.GetLocaleStringResourceById(model.Id);

            // if the resourceName changed, ensure it isn't being used by another resource
            if (!resource.ResourceName.Equals(model.ResourceName, StringComparison.InvariantCultureIgnoreCase))
            {
                var res = _localizationService.GetLocaleStringResourceByName(model.ResourceName, model.LanguageId, false);
                if (res != null && res.Id != resource.Id)
                {
                    return(Json(new DataSourceResult {
                        Errors = string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), res.ResourceName)
                    }));
                }
            }

            //fill entity from model
            resource = model.ToEntity(resource);

            _localizationService.UpdateLocaleStringResource(resource);

            return(new NullJsonResult());
        }
Ejemplo n.º 2
0
        public virtual IActionResult ResourceAdd(int languageId, LocaleResourceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.ResourceName != null)
            {
                model.ResourceName = model.ResourceName.Trim();
            }
            if (model.ResourceValue != null)
            {
                model.ResourceValue = model.ResourceValue.Trim();
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var res = _localizationService.GetLocaleStringResourceByName(model.ResourceName, model.LanguageId, false);

            if (res == null)
            {
                //fill entity from model
                var resource = model.ToEntity <LocaleStringResource>();

                resource.LanguageId = languageId;

                _localizationService.InsertLocaleStringResource(resource);
            }
            else
            {
                return(Json(new DataSourceResult {
                    Errors = string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), model.ResourceName)
                }));
            }

            return(new NullJsonResult());
        }
Ejemplo n.º 3
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> ResourceAdd(int languageId, [Validate] LocaleResourceModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.ResourceName != null)
            {
                model.ResourceName = model.ResourceName.Trim();
            }
            if (model.ResourceValue != null)
            {
                model.ResourceValue = model.ResourceValue.Trim();
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            var res = await _localizationService.GetLocaleStringResourceByNameAsync(model.ResourceName, model.LanguageId, false);

            if (res == null)
            {
                //fill entity from model
                var resource = model.ToEntity <LocaleStringResource>();

                resource.LanguageId = languageId;

                await _localizationService.InsertLocaleStringResourceAsync(resource);
            }
            else
            {
                return(ErrorJson(string.Format(await _localizationService.GetResourceAsync("Admin.Configuration.Languages.Resources.NameAlreadyExists"), model.ResourceName)));
            }

            return(Json(new { Result = true }));
        }