public ActionResult Index(ThemesViewModel model, IFormCollection collection) { ThemesViewModel model2 = new ThemesViewModel(); try { int itemsPerPage = 6; int currentPage = model.PageNumber; string next = collection["next"]; string prev = collection["prev"]; if (next != null) { currentPage++; } if (prev != null) { currentPage--; } IRequestCultureFeature culture = Request.HttpContext.Features.Get <IRequestCultureFeature>(); List <ThemeInfo> themeInfoList = Configuration.ThemeHelper.GetInstalledThemesInfo(culture); themeInfoList.OrderBy(o => o.ThemeName); ThemeInfo currentTheme = themeInfoList.Where(i => i.ThemeName == Configuration.GlobalWebsiteConfig.ThemeName).First(); themeInfoList.Remove(currentTheme); themeInfoList.Insert(0, currentTheme); JasperPaging <ThemeInfo> paging = new JasperPaging <ThemeInfo>(themeInfoList, currentPage, itemsPerPage); model2.SelectedThemeName = Configuration.GlobalWebsiteConfig.ThemeName; model2.ThemeFolder = Configuration.ThemeFolder; model2.PageNumber = paging.CurrentPageNumber; model2.ItemsPerPage = paging.ItemsPerPage; model2.TotalNumberOfPages = paging.NumberOfPagesNeeded; model2.ThemeInfoList = paging.GetCurrentPageItems(); } catch { TempData["ErrorMessage"] = "Při provádění pořadavku došlo k chybě"; } bool isAjaxRequest = Request.Headers["x-requested-with"] == "XMLHttpRequest"; if (isAjaxRequest) { ModelState.Clear(); return(PartialView("ThemesPartialView", model2)); } else { return(RedirectToAction("Index")); } }
public ThemesViewModel UpdatePage() { try { int itemsPerPage = 6; int currentPage = 1; IRequestCultureFeature culture = Request.HttpContext.Features.Get <IRequestCultureFeature>(); // Theme description path is based on locale e.g. (desc.cs.txt) for the Czech language List <ThemeInfo> themeInfoList = Configuration.ThemeHelper.GetInstalledThemesInfoByNameAndActive(culture); JasperPaging <ThemeInfo> paging = new JasperPaging <ThemeInfo>(themeInfoList, currentPage, itemsPerPage); ThemesViewModel model = new ThemesViewModel(); model.SelectedThemeName = Configuration.GlobalWebsiteConfig.ThemeName; model.ThemeFolder = Configuration.ThemeFolder; model.PageNumber = paging.CurrentPageNumber; model.ItemsPerPage = paging.ItemsPerPage; model.TotalNumberOfPages = paging.NumberOfPagesNeeded; model.ThemeInfoList = paging.GetCurrentPageItems(); // Not registered themes check model.NotRegisteredThemeNames = dbHelper.CheckThemeFolderAndDatabaseIntegrity(culture); model.ManuallyDeletedThemeNames = dbHelper.FindManuallyDeletedThemes(culture); return(model); } catch (ThemeNotExistsException ex) // specified theme of jasper.json property "themeName" does not exist { ThemesViewModel model = new ThemesViewModel(); model.ItemsPerPage = 3; model.ManuallyDeletedThemeNames = null; model.NotRegisteredThemeNames = null; model.PageNumber = 1; model.SelectedThemeName = "Globální soubor jasper.json uvádí jako vzhled: " + ex.MissingThemeName + " který ale ve složce " + Configuration.ThemeFolder + " neexistuje"; model.ThemeFolder = Configuration.ThemeFolder; model.ThemeInfoList = null; model.TotalNumberOfPages = default(int); return(model); } catch { ThemesViewModel model = new ThemesViewModel(); model.ItemsPerPage = 3; model.ManuallyDeletedThemeNames = null; model.NotRegisteredThemeNames = null; model.PageNumber = 1; model.SelectedThemeName = null; model.ThemeFolder = null; model.ThemeInfoList = null; model.TotalNumberOfPages = default(int); return(model); } }
public ArticleListViewModel UpdateArticleListModel(int currentPage, int itemsPerPage) { ArticleListViewModel modelOutput = new ArticleListViewModel(); List <Article> articleList = dbHelper.GetAllArticles(); articleList.OrderBy(a => a.Name); JasperPaging <Article> paging = new JasperPaging <Article>(articleList, currentPage, itemsPerPage); modelOutput.CurrentPage = paging.CurrentPageNumber; modelOutput.TotalNumberOfPages = paging.NumberOfPagesNeeded; modelOutput.Articles = paging.GetCurrentPageItems(); return(modelOutput); }