Exemplo n.º 1
0
        public IActionResult SaveJasperJson(JasperJsonViewModel model)
        {
            // In case of error old settings will be restored
            string oldSettingsBackup = Configuration.GlobalWebsiteConfig.GetGlobalJsonFileAsString();

            bool isAjaxRequest = Request.Headers["x-requested-with"] == "XMLHttpRequest";

            try
            {
                Configuration.GlobalWebsiteConfig.SaveGlobalJsonFileAsString(model.JasperJson);
                Configuration.Initialize();
                TempData["Success"] = true;
            }
            catch
            {
                TempData["ErrorMessage"] = "Změny nemohly být provedeny";

                // Restore old settings
                Configuration.GlobalWebsiteConfig.SaveGlobalJsonFileAsString(oldSettingsBackup);
            }

            if (isAjaxRequest)
            {
                ModelState.Clear(); // Updating model in POST

                // Fresh data (without previously entered errors) will be served
                return(PartialView("JasperJsonPartialView", UpdateJasperJsonViewModel()));
            }
            else
            {
                return(RedirectToAction("Index", UpdatePage()));
            }
        }
Exemplo n.º 2
0
        public JasperJsonViewModel UpdateJasperJsonViewModel()
        {
            JasperJsonViewModel model = new JasperJsonViewModel();

            try
            {
                model.JasperJson = Configuration.GlobalWebsiteConfig.GetGlobalJsonFileAsString();
                return(model);
            }
            catch
            {
                model.JasperJson = string.Empty;
                return(model);
            }
        }