public IActionResult FetchThemeJasperJsonData(int themeId) { string themeName = _dbHelper.GetAllThemes().Where(t => t.Id == themeId).Single().Name; string jsonThemeData = Configuration.WebsiteConfig.GetThemeJsonFileAsString(themeName); JasperJsonThemeViewModel model = new JasperJsonThemeViewModel(); model.JasperJson = jsonThemeData; // currently selected theme will be first in the list List <Theme> allThemes = _dbHelper.GetAllThemes(); Theme themeBeingShown = allThemes.Where(t => t.Id == themeId).Single(); allThemes.Remove(themeBeingShown); allThemes.Insert(0, themeBeingShown); // currently activated theme will be marked int currentThemeid = _dbHelper.GetCurrentThemeIdFromDb(); allThemes.Where(t => t.Id == currentThemeid).Single().Name += " " + _localizer["(active)"]; model.Themes = allThemes; return(PartialView("JasperJsonThemePartialView", model)); }
public IActionResult PostThemeJasperJsonData(JasperJsonThemeViewModel viewModel) { bool isAjaxRequest = Request.Headers["x-requested-with"] == "XMLHttpRequest"; int selectedThemeId = viewModel.SelectedThemeId; string themeNameToBeUpdated = _dbHelper.GetAllThemes().Where(t => t.Id == selectedThemeId).Single().Name; string oldDataBackup = string.Empty; try { oldDataBackup = Configuration.WebsiteConfig.GetThemeJsonFileAsString(themeNameToBeUpdated); string newJsonData = viewModel.JasperJson; Configuration.WebsiteConfig.SaveThemeJsonFileAsString(newJsonData, themeNameToBeUpdated); IRequestCultureFeature culture = Request.HttpContext.Features.Get <IRequestCultureFeature>(); Configuration.ThemeHelper.UpdateAllThemeRelatedData(_databaseContext, culture); // apply changes TempData["Success"] = true; } catch { TempData["ErrorMessage"] = "Soubor nebylo možné aktualizovat."; // revert chages Configuration.WebsiteConfig.SaveThemeJsonFileAsString(oldDataBackup, themeNameToBeUpdated); } JasperJsonThemeViewModel model = new JasperJsonThemeViewModel(); model.JasperJson = Configuration.WebsiteConfig.GetThemeJsonFileAsString(themeNameToBeUpdated); // currently selected theme will be first in the list List <Theme> allThemes = _dbHelper.GetAllThemes(); Theme themeBeingShown = allThemes.Where(t => t.Id == selectedThemeId).Single(); allThemes.Remove(themeBeingShown); allThemes.Insert(0, themeBeingShown); // currently activated theme will be marked int currentThemeid = _dbHelper.GetCurrentThemeIdFromDb(); allThemes.Where(t => t.Id == currentThemeid).Single().Name += " " + _localizer["(active)"]; model.Themes = allThemes; ModelState.Clear(); if (isAjaxRequest) { return(PartialView("JasperJsonThemePartialView", model)); } else { return(RedirectToAction("Index")); } }
private JasperJsonThemeViewModel UpdateJasperJsonThemeViewModel() { JasperJsonThemeViewModel model = new JasperJsonThemeViewModel(); model.JasperJson = Configuration.WebsiteConfig.GetThemeJsonFileAsString(); model.Themes = OrderAllThemesByActive(); return(model); }