Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prepare locale resource search model
        /// </summary>
        /// <param name="searchModel">Locale resource search model</param>
        /// <param name="language">Language</param>
        /// <returns>Locale resource search model</returns>
        protected virtual LocaleResourceSearchModel PrepareLocaleResourceSearchModel(LocaleResourceSearchModel searchModel, Language language)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            searchModel.LanguageId = language.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Ejemplo n.º 3
0
        public virtual IActionResult Resources(LocaleResourceSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageLanguages))
            {
                return(AccessDeniedKendoGridJson());
            }

            //try to get a language with the specified id
            var language = _languageService.GetLanguageById(searchModel.LanguageId, false);

            if (language == null)
            {
                return(RedirectToAction("List"));
            }

            //prepare model
            var model = _languageModelFactory.PrepareLocaleResourceListModel(searchModel, language);

            return(Json(model));
        }
Ejemplo n.º 4
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> Resources(LocaleResourceSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageLanguages))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get a language with the specified id
            var language = await _languageService.GetLanguageByIdAsync(searchModel.LanguageId);

            if (language == null)
            {
                return(RedirectToAction("List"));
            }

            //prepare model
            var model = await _languageModelFactory.PrepareLocaleResourceListModelAsync(searchModel, language);

            return(Json(model));
        }
Ejemplo n.º 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 async Task <LocaleResourceListModel> PrepareLocaleResourceListModelAsync(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 = (await _localizationService.GetAllResourceValuesAsync(language.Id, loadPublicLocales: null))
                                  .OrderBy(localeResource => localeResource.Key).AsQueryable();

            //filter locale resources
            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 = await localeResources.ToPagedListAsync(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);
        }