Ejemplo n.º 1
0
        /// <summary>
        ///     Search through all resources for a language by page and search terms.
        ///     Search either by key or value.
        /// </summary>
        /// <param name="searchByKey">True means serach the keys else search the values</param>
        /// <param name="languageId"></param>
        /// <param name="p"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        private async Task <ActionResult> GetLanguageResources(bool searchByKey, Guid languageId, int?p, string search)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = (from key in ModelState.Keys
                                  select ModelState[key]
                                  into state
                                  where state.Errors.Any()
                                  select state.Errors.First().ErrorMessage).ToList();
                    ShowErrors(errors);
                }
                else
                {
                    var language  = LocalizationService.Get(languageId);
                    var pageIndex = p ?? 1;

                    // Get all the resources or just the ones that match the search
                    var allResources = string.IsNullOrWhiteSpace(search)
                        ? await LocalizationService.GetAllValues(language.Id, pageIndex,
                                                                 ForumConfiguration.Instance.AdminListPageSize)
                        : searchByKey
                            ? await LocalizationService.SearchResourceKeys(language.Id, search,
                                                                           pageIndex,
                                                                           ForumConfiguration.Instance.AdminListPageSize)
                            : await LocalizationService.SearchResourceValues(language.Id, search,
                                                                             pageIndex,
                                                                             ForumConfiguration.Instance.AdminListPageSize);

                    var models = allResources.Select(resource => new LocaleResourceViewModel
                    {
                        Id                = resource.Id,
                        ResourceKeyId     = resource.LocaleResourceKey.Id,
                        LocaleResourceKey = resource.LocaleResourceKey.Name,
                        ResourceValue     = resource.ResourceValue
                    }).ToList();

                    var resourceListModel = new LanguageListResourcesViewModel
                    {
                        LanguageId      = language.Id,
                        LanguageName    = language.Name,
                        LocaleResources = models,
                        PageIndex       = pageIndex,
                        TotalCount      = allResources.TotalCount,
                        Search          = search,
                        TotalPages      = allResources.TotalPages
                    };

                    return(View("ListValues", resourceListModel));
                }
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }

            // Default ie error
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult ManageLanguageResourceValues(Guid languageId, int?p, string search = "", string SearchKeys = "")
        {
            var language = LocalizationService.Get(languageId);

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

            int limit = 30;
            var count = LocalizationService.GetListKeyResourceCount(language.Id, SearchKeys, search);

            var Paging = CalcPaging(limit, p, count);

            var resourceListModel = new LanguageListResourcesViewModel
            {
                LanguageId      = language.Id,
                LanguageName    = language.Name,
                Search          = search,
                SearchKeys      = SearchKeys,
                Paging          = Paging,
                LocaleResources = LocalizationService.GetListKeyResource(language.Id, SearchKeys, search, Paging.Page, limit)
            };

            return(View("ListValues", resourceListModel));
        }
Ejemplo n.º 3
0
        private ActionResult GetLanguageResources(bool searchByKey, Guid languageId, int?p, string search)
        {
            try
            {
                using (UnitOfWorkManager.NewUnitOfWork())
                {
                    var language = LocalizationService.Get(languageId);

                    int count   = LocalizationService.GetCountResourceKey();
                    int limit   = 30;
                    int MaxPage = count / limit;
                    if (count % limit > 0)
                    {
                        MaxPage++;
                    }
                    if (MaxPage == 0)
                    {
                        MaxPage = 1;
                    }

                    if (p == null)
                    {
                        p = 1;
                    }
                    if (p > MaxPage)
                    {
                        p = MaxPage;
                    }

                    var resources = LocalizationService.GetListResourceKey((int)p, limit);

                    var resourceListModel = new LanguageListResourcesViewModel
                    {
                        LanguageId      = language.Id,
                        LanguageName    = language.Name,
                        LocaleResources = new List <LocaleResourceViewModel>(),
                        PageIndex       = p,
                        TotalCount      = count,
                        Search          = search,
                        TotalPages      = MaxPage
                    };

                    foreach (var it in resources)
                    {
                        var ResourceString = LocalizationService.GetValueResource(it.Id, languageId);

                        if (ResourceString == null)
                        {
                            ResourceString = new LocaleStringResource {
                                ResourceValue = ""
                            }
                        }
                        ;

                        resourceListModel.LocaleResources.Add(new LocaleResourceViewModel {
                            Id                = ResourceString.Id,
                            ResourceKeyId     = it.Id,
                            LocaleResourceKey = it.Name,
                            ResourceValue     = ResourceString.ResourceValue
                        });
                    }



                    return(View("ListValues", resourceListModel));
                }
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }

            // Default ie error
            return(RedirectToAction("Index"));
        }