Example #1
0
        public ActionResult Resources(int languageId, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            var language = _languageService.GetLanguageById(languageId);

            var resources = _localizationService
                            .GetAllResourceValues(languageId)
                            .OrderBy(x => x.Key)
                            .Select(x => new LanguageResourceModel()
            {
                LanguageId   = languageId,
                LanguageName = language.Name,
                Id           = x.Value.Key,
                Name         = x.Key,
                Value        = x.Value.Value,
            })
                            .ForCommand(command)
                            .ToList();

            var model = new GridModel <LanguageResourceModel>
            {
                Data  = resources.PagedForCommand(command),
                Total = resources.Count
            };

            return(new JsonResult
            {
                Data = model
            });
        }
Example #2
0
		public ActionResult Resources(int languageId, DataSourceRequest command, LanguageResourcesListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
                return AccessDeniedView();

            var query = _localizationService
                .GetAllResourceValues(languageId)
                .OrderBy(x => x.Key)
                .AsQueryable();

            if (!string.IsNullOrEmpty(model.SearchResourceName))
                query = query.Where(l => l.Key.ToLowerInvariant().Contains(model.SearchResourceName.ToLowerInvariant()));
            if (!string.IsNullOrEmpty(model.SearchResourceValue))
                query = query.Where(l => l.Value.Value.ToLowerInvariant().Contains(model.SearchResourceValue.ToLowerInvariant()));

            var resources = query
                .Select(x => new LanguageResourceModel
                    {
                        LanguageId = languageId,
                        Id = x.Value.Key,
                        Name = x.Key,
                        Value = x.Value.Value,
                    });
            
            var gridModel = new DataSourceResult
            {
                Data = resources.PagedForCommand(command),
                Total = resources.Count()
            };

            return Json(gridModel);
		}
        public ActionResult Resources(long languageId, DataSourceRequest command, LanguageResourcesListModel model)
        {
            var query = _localizationService
                        .GetAllResourceValues(languageId)
                        .OrderBy(x => x.Key)
                        .AsQueryable();

            if (!string.IsNullOrEmpty(model.SearchResourceName))
            {
                query = query.Where(l => l.Key.ToLowerInvariant().Contains(model.SearchResourceName.ToLowerInvariant()));
            }
            if (!string.IsNullOrEmpty(model.SearchResourceValue))
            {
                query = query.Where(l => l.Value.Value.ToLowerInvariant().Contains(model.SearchResourceValue.ToLowerInvariant()));
            }

            var resources = query
                            .Select(x => new
            {
                LanguageId = languageId,
                Id         = x.Value.Key,
                Name       = x.Key,
                Value      = x.Value.Value,
            });

            var gridModel = new DataSourceResult
            {
                Data  = resources.PagedForCommand(command),
                Total = resources.Count()
            };

            return(Json(gridModel));
        }
        public ActionResult Resources(int languageId, DataSourceRequest command,
                                      Nop.Web.Framework.Kendoui.Filter filter = null, IEnumerable <Sort> sort = null)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            var language = _languageService.GetLanguageById(languageId);

            var resources = _localizationService
                            .GetAllResourceValues(languageId)
                            .OrderBy(x => x.Key)
                            .Select(x => new LanguageResourceModel
            {
                LanguageId   = languageId,
                LanguageName = language.Name,
                Id           = x.Value.Key,
                Name         = x.Key,
                Value        = x.Value.Value,
            })
                            .AsQueryable()
                            .Filter(filter)
                            .Sort(sort);

            var gridModel = new DataSourceResult
            {
                Data  = resources.PagedForCommand(command),
                Total = resources.Count()
            };

            return(Json(gridModel));
        }
Example #5
0
        /// <summary>
        /// Prepare paged locale resource list model
        /// </summary>
        /// <param name="searchModel">Locale resource search model</param>
        /// <param name="language">Language</param>
        /// <returns>Locale resource list model</returns>
        public virtual LocaleResourceListModel PrepareLocaleResourceListModel(LocaleResourceSearchModel searchModel, Language language)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (language == null)
            {
                throw new ArgumentNullException(nameof(language));
            }

            //get locale resources
            var localeResources = _localizationService.GetAllResourceValues(language.Id, loadPublicLocales: null)
                                  .OrderBy(localeResource => localeResource.Key).AsQueryable();

            //filter locale resources
            //TODO: move filter to language service
            if (!string.IsNullOrEmpty(searchModel.SearchResourceName))
            {
                localeResources = localeResources.Where(l => l.Key.ToLowerInvariant().Contains(searchModel.SearchResourceName.ToLowerInvariant()));
            }
            if (!string.IsNullOrEmpty(searchModel.SearchResourceValue))
            {
                localeResources = localeResources.Where(l => l.Value.Value.ToLowerInvariant().Contains(searchModel.SearchResourceValue.ToLowerInvariant()));
            }

            //prepare list model
            var model = new LocaleResourceListModel
            {
                //fill in model values from the entity
                Data = localeResources.PaginationByRequestModel(searchModel).Select(localeResource => new LocaleResourceModel
                {
                    LanguageId = language.Id,
                    Id         = localeResource.Value.Key,
                    Name       = localeResource.Key,
                    Value      = localeResource.Value.Value
                }),
                Total = localeResources.Count()
            };

            return(model);
        }
Example #6
0
        public ActionResult Resources(int languageId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedView());
            }

            ViewBag.AllLanguages = _languageService.GetAllLanguages(true)
                                   .Select(x => new SelectListItem
            {
                Selected = (x.Id.Equals(languageId)),
                Text     = x.Name,
                Value    = x.Id.ToString()
            }).ToList();
            var language = _languageService.GetLanguageById(languageId);

            ViewBag.LanguageId   = languageId;
            ViewBag.LanguageName = language.Name;

            var resources = _localizationService
                            .GetAllResourceValues(languageId)
                            .OrderBy(x => x.Key)
                            .ToList();
            var gridModel = new GridModel <LanguageResourceModel>
            {
                Data = resources
                       .Take(_adminAreaSettings.GridPageSize)
                       .Select(x => new LanguageResourceModel()
                {
                    LanguageId   = languageId,
                    LanguageName = language.Name,
                    Id           = x.Value.Key,
                    Name         = x.Key,
                    Value        = x.Value.Value,
                }),
                Total = resources.Count
            };

            return(View(gridModel));
        }
        /// <summary>
        /// 准备语言资源文件
        /// </summary>
        /// <param name="languageId"></param>
        /// <returns></returns>
        public DataSourceResult PrepareLocaleResourceListModel(DataSourceRequest command, int languageId)
        {
            if (languageId == 0)
            {
                throw new ArgumentNullException("model");
            }
            var localResources = _localizationService.GetAllResourceValues(languageId
                                                                           , null, null, pageIndex: command.Page - 1,
                                                                           pageSize: command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data  = localResources.Select(PrepareLocaleResourceModel),
                Total = localResources.Count
            };

            return(gridModel);
        }
Example #8
0
        /// <summary>
        /// Prepare paged locale resource list model
        /// </summary>
        /// <param name="searchModel">Locale resource search model</param>
        /// <param name="language">Language</param>
        /// <returns>Locale resource list model</returns>
        public virtual LocaleResourceListModel PrepareLocaleResourceListModel(LocaleResourceSearchModel searchModel, Language language)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (language == null)
            {
                throw new ArgumentNullException(nameof(language));
            }

            //get locale resources
            var localeResources = _localizationService.GetAllResourceValues(language.Id, loadPublicLocales: null)
                                  .OrderBy(localeResource => localeResource.Key).AsQueryable();

            //filter locale resources
            //TODO: move filter to language service
            if (!string.IsNullOrEmpty(searchModel.SearchResourceName))
            {
                localeResources = localeResources.Where(l => l.Key.ToLowerInvariant().Contains(searchModel.SearchResourceName.ToLowerInvariant()));
            }
            if (!string.IsNullOrEmpty(searchModel.SearchResourceValue))
            {
                localeResources = localeResources.Where(l => l.Value.Value.ToLowerInvariant().Contains(searchModel.SearchResourceValue.ToLowerInvariant()));
            }

            var pagedLocaleResources = new PagedList <KeyValuePair <string, KeyValuePair <int, string> > >(localeResources,
                                                                                                           searchModel.Page - 1, searchModel.PageSize);

            //prepare list model
            var model = new LocaleResourceListModel().PrepareToGrid(searchModel, pagedLocaleResources, () =>
            {
                //fill in model values from the entity
                return(pagedLocaleResources.Select(localeResource => new LocaleResourceModel
                {
                    LanguageId = language.Id,
                    Id = localeResource.Value.Key,
                    ResourceName = localeResource.Key,
                    ResourceValue = localeResource.Value.Value
                }));
            });

            return(model);
        }
Example #9
0
        public IActionResult GetAllResourceValues(int languageId)
        {
            var model = _localizationService.GetAllResourceValues(languageId).ToList();

            return(Ok(model));
        }
Example #10
0
 /// <summary>
 /// Gets all locale string resources by language identifier
 /// </summary>
 /// <param name="languageId">Language identifier</param>
 /// <returns>Locale string resources</returns>
 public Dictionary <string, KeyValuePair <int, string> > GetAllResourceValues(int languageId)
 {
     return(_localizationService.GetAllResourceValues(languageId));
 }