Ejemplo n.º 1
0
        public ActionResult Resources(int languageId, GridCommand command)
        {
            var model = new GridModel <LanguageResourceModel>();

            var language  = _languageService.GetLanguageById(languageId);
            var resources = _services.Localization.All(languageId).ForCommand(command);

            model.Data = resources.PagedForCommand(command).ToList().Select(x =>
            {
                var resModel = new LanguageResourceModel
                {
                    Id            = x.Id,
                    LanguageId    = languageId,
                    LanguageName  = language.Name,
                    ResourceName  = x.ResourceName,
                    ResourceValue = x.ResourceValue.EmptyNull(),
                };

                return(resModel);
            });

            model.Total = resources.AsQueryable().Count();

            return(new JsonResult
            {
                Data = model
            });
        }
Ejemplo n.º 2
0
        public ActionResult ResourceAdd(int languageId, [Bind(Exclude = "Id")] LanguageResourceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
                return AccessDeniedView();

            if (model.Name != null)
                model.Name = model.Name.Trim();
            if (model.Value != null)
                model.Value = model.Value.Trim();

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

            var res = _localizationService.GetLocaleStringResourceByName(model.Name, model.LanguageId, false);
            if (res == null)
            {
                var resource = new LocaleStringResource { LanguageId = languageId };
                resource.ResourceName = model.Name;
                resource.ResourceValue = model.Value;
                _localizationService.InsertLocaleStringResource(resource);
            }
            else
            {
                return Json(new DataSourceResult { Errors = string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), model.Name) });
            }

            return new NullJsonResult();
        }
Ejemplo n.º 3
0
 private void PrepareResourceModel(LanguageResourceModel model, LocaleStringResource resource, bool excludeProperties)
 {
     if (model == null)
     {
         throw new ArgumentNullException("model");
     }
     if (!excludeProperties)
     {
         if (resource != null)
         {
             model.Name       = resource.ResourceName;
             model.Value      = resource.ResourceValue;
             model.Id         = resource.Id;
             model.LanguageId = resource.LanguageId;
         }
     }
     else
     {
         if (model != null)
         {
             resource.ResourceName  = model.Name;
             resource.ResourceValue = model.Value;
         }
     }
 }
Ejemplo n.º 4
0
        public virtual (bool error, string message) UpdateLanguageResourceModel(LanguageResourceModel model)
        {
            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }
            var resource = _localizationService.GetLocaleStringResourceById(model.Id);

            // if the resourceName changed, ensure it isn't being used by another resource
            if (!resource.ResourceName.Equals(model.Name, StringComparison.OrdinalIgnoreCase))
            {
                var res = _localizationService.GetLocaleStringResourceByName(model.Name, model.LanguageId, false);
                if (res != null && res.Id != resource.Id)
                {
                    return(error : true, message : string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), res.ResourceName));
                }
            }
            resource.ResourceName  = model.Name;
            resource.ResourceValue = model.Value;
            _localizationService.UpdateLocaleStringResource(resource);
            return(false, string.Empty);
        }
Ejemplo n.º 5
0
        public virtual (bool error, string message) InsertLanguageResourceModel(LanguageResourceModel model)
        {
            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

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

            if (res == null)
            {
                var resource = new LocaleStringResource {
                    LanguageId = model.LanguageId
                };
                resource.ResourceName  = model.Name;
                resource.ResourceValue = model.Value;
                _localizationService.InsertLocaleStringResource(resource);
            }
            else
            {
                return(error : true, message : string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), model.Name));
            }
            return(false, string.Empty);
        }
Ejemplo n.º 6
0
        public ActionResult ResourceUpdate(LanguageResourceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
                return AccessDeniedView();

            if (model.Name != null)
                model.Name = model.Name.Trim();
            if (model.Value != null)
                model.Value = model.Value.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.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                var res = _localizationService.GetLocaleStringResourceByName(model.Name, 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) });
                }
            }

            resource.ResourceName = model.Name;
            resource.ResourceValue = model.Value;
            _localizationService.UpdateLocaleStringResource(resource);

            return new NullJsonResult();
        }
Ejemplo n.º 7
0
        //create
        public ActionResult OptionCreatePopup(int languageId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            var model = new LanguageResourceModel();

            model.LanguageId = languageId;


            return(View(model));
        }
        public IActionResult ResourceAdd(LanguageResourceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }
            var result = _languageViewModelService.InsertLanguageResourceModel(model);

            if (result.error)
            {
                return(ErrorForKendoGridJson(result.message));
            }
            return(new NullJsonResult());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> ResourceAdd(LanguageResourceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }
            var(error, message) = await _languageViewModelService.InsertLanguageResourceModel(model);

            if (error)
            {
                return(ErrorForKendoGridJson(message));
            }
            return(new NullJsonResult());
        }
Ejemplo n.º 10
0
        public ActionResult OptionEditPopup(string btnId, string formId, LanguageResourceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

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

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

            ViewBag.RefreshPage    = true;
            ViewBag.btnId          = btnId;
            ViewBag.formId         = formId;
            resource.ResourceName  = model.Name;
            resource.ResourceValue = model.Value;
            resource.IsTouched     = true;
            _localizationService.UpdateLocaleStringResource(resource);

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult OptionCreatePopup(string btnId, string formId, LanguageResourceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

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

            if (res == null)
            {
                var resource = new LocaleStringResource {
                    LanguageId = model.LanguageId
                };
                resource.ResourceName  = model.Name;
                resource.ResourceValue = model.Value;
                resource.IsTouched     = true;
                _localizationService.InsertLocaleStringResource(resource);
            }
            else
            {
                return(Content(string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), model.Name)));
            }
            ViewBag.RefreshPage = true;
            ViewBag.btnId       = btnId;
            ViewBag.formId      = formId;

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 12
0
        public ActionResult ResourceAdd(int id, LanguageResourceModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

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

            if (res == null)
            {
                var resource = new LocaleStringResource {
                    LanguageId = id
                };
                resource.ResourceName  = model.Name;
                resource.ResourceValue = model.Value;
                resource.IsTouched     = true;
                _localizationService.InsertLocaleStringResource(resource);
            }
            else
            {
                return(Content(string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), model.Name)));
            }
            return(Resources(id, command));
        }
Ejemplo n.º 13
0
        public ActionResult ResourceUpdate(LanguageResourceModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

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

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

            resource.ResourceName  = model.Name;
            resource.ResourceValue = model.Value;
            _localizationService.UpdateLocaleStringResource(resource);

            return(Resources(model.LanguageId, command));
        }
Ejemplo n.º 14
0
        //edit
        public ActionResult OptionEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            var resource = _localizationService.GetLocaleStringResourceById(id);

            if (resource == null)
            {
                //No specification attribute option found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new LanguageResourceModel();

            PrepareResourceModel(model, resource, false);

            return(View(model));
        }
Ejemplo n.º 15
0
        public ActionResult ResourceUpdate(LanguageResourceModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

            if (!ModelState.IsValid)
            {
                return(new JsonResult {
                    Data = "error"
                });
            }

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

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

            resource = model.ToEntity(resource);
            _localizationService.UpdateLocaleStringResource(resource);

            return(Resources(model.LanguageId, command));
        }
Ejemplo n.º 16
0
        public ActionResult ResourceAdd(int id, LanguageResourceModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

            if (!ModelState.IsValid)
            {
                return(new JsonResult {
                    Data = "error"
                });
            }

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

            if (res == null)
            {
                var resource = new LocaleStringResource {
                    LanguageId = id
                };
                resource = model.ToEntity(resource);
                _localizationService.InsertLocaleStringResource(resource);
            }
            else
            {
                return(Content(string.Format(_localizationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), res.ResourceName)));
            }
            return(Resources(id, command));
        }
Ejemplo n.º 17
0
        public ActionResult Resources(int languageId, GridCommand command)
        {
            var model = new GridModel <LanguageResourceModel>();

            if (_services.Permissions.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                var language = _languageService.GetLanguageById(languageId);

                var resources = _services.Localization.All(languageId).ForCommand(command);

                model.Data = resources.PagedForCommand(command).ToList().Select(x =>
                {
                    var resModel = new LanguageResourceModel
                    {
                        Id            = x.Id,
                        LanguageId    = languageId,
                        LanguageName  = language.Name,
                        ResourceName  = x.ResourceName,
                        ResourceValue = x.ResourceValue.EmptyNull(),
                    };

                    return(resModel);
                });

                model.Total = resources.AsQueryable().Count();
            }
            else
            {
                model.Data = Enumerable.Empty <LanguageResourceModel>();

                NotifyAccessDenied();
            }

            return(new JsonResult
            {
                Data = model
            });
        }
        public ActionResult ResourceUpdate(LanguageResourceModel model)
        {
            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.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.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                var res = _localizationService.GetLocaleStringResourceByName(model.Name, model.LanguageId, false);
                if (res != null && res.Id != resource.Id)
                {
                    return(Json(new DataSourceResult {
                        Errors = string.Format(_localizationService.GetResource("LanguageResource.NameAlreadyExists"), res.ResourceName)
                    }));
                }
            }

            resource.ResourceName  = model.Name;
            resource.ResourceValue = model.Value;
            _localizationService.UpdateLocaleStringResource(resource);

            return(new NullJsonResult());
        }
Ejemplo n.º 19
0
        public ActionResult ResourceUpdate(LanguageResourceModel model, GridCommand command)
        {
            if (model.ResourceName != null)
            {
                model.ResourceName = model.ResourceName.Trim();
            }

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

            if (!ModelState.IsValid)
            {
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var resource = _services.Localization.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 = _services.Localization.GetLocaleStringResourceByName(model.ResourceName, model.LanguageId, false);
                if (res != null && res.Id != resource.Id)
                {
                    return(Content(T("Admin.Configuration.Languages.Resources.NameAlreadyExists", res.ResourceName)));
                }
            }

            resource.ResourceName  = model.ResourceName;
            resource.ResourceValue = model.ResourceValue;
            resource.IsTouched     = true;

            _services.Localization.UpdateLocaleStringResource(resource);

            return(Resources(model.LanguageId, command));
        }
        public ActionResult ResourceAdd(long languageId, [Bind(Exclude = "Id")] LanguageResourceModel model)
        {
            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

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

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

            if (res == null)
            {
                var resource = new LocaleStringResource {
                    LanguageId = languageId
                };
                resource.ResourceName  = model.Name;
                resource.ResourceValue = model.Value;
                _localizationService.InsertLocaleStringResource(resource);
            }
            else
            {
                return(Json(new DataSourceResult {
                    Errors = string.Format(_localizationService.GetResource("LanguageResource.NameAlreadyExists"), model.Name)
                }));
            }

            return(new NullJsonResult());
        }
Ejemplo n.º 21
0
        public ActionResult ResourceAdd(int id, LanguageResourceModel model, GridCommand command)
        {
            if (model.ResourceName != null)
            {
                model.ResourceName = model.ResourceName.Trim();
            }
            if (model.ResourceValue != null)
            {
                model.ResourceValue = model.ResourceValue.Trim();
            }

            if (!ModelState.IsValid)
            {
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

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

            if (res == null)
            {
                var resource = new LocaleStringResource {
                    LanguageId = id
                };
                resource.ResourceName  = model.ResourceName;
                resource.ResourceValue = model.ResourceValue;
                resource.IsTouched     = true;

                _services.Localization.InsertLocaleStringResource(resource);
            }
            else
            {
                return(Content(T("Admin.Configuration.Languages.Resources.NameAlreadyExists", model.ResourceName)));
            }

            return(Resources(id, command));
        }
Ejemplo n.º 22
0
        public virtual async Task <(bool error, string message)> InsertLanguageResourceModel(LanguageResourceModel model)
        {
            if (model.Name != null)
            {
                model.Name = model.Name.Trim();
            }
            if (model.Value != null)
            {
                model.Value = model.Value.Trim();
            }

            var res = await _translationService.GetTranslateResourceByName(model.Name, model.LanguageId);

            if (res == null)
            {
                var resource = new TranslationResource {
                    LanguageId = model.LanguageId
                };
                resource.Name  = model.Name;
                resource.Value = model.Value;
                await _translationService.InsertTranslateResource(resource);
            }
            else
            {
                return(error : true, message : string.Format(_translationService.GetResource("Admin.Configuration.Languages.Resources.NameAlreadyExists"), model.Name));
            }
            return(false, string.Empty);
        }
Ejemplo n.º 23
0
 public static LocaleStringResource ToEntity(this LanguageResourceModel model)
 {
     return(Mapper.Map <LanguageResourceModel, LocaleStringResource>(model));
 }
Ejemplo n.º 24
0
 public static LocaleStringResource ToEntity(this LanguageResourceModel model, LocaleStringResource destination)
 {
     return(Mapper.Map(model, destination));
 }