示例#1
0
        public IActionResult SaveSettings(SettingsNameViewModel model)
        {
            bool isAjaxRequest = Request.Headers["x-requested-with"] == "XMLHttpRequest";

            try
            {
                if (ModelState.IsValid)
                {
                    _dbHelper.SetWebsiteName(model.WebsiteName);
                    TempData["Success"] = true;
                }
                else
                {
                    throw new Exception();
                }
            }
            catch
            {
                TempData["ErrorMessage"] = "Změny nemohly být provedeny";
            }

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

                // Fresh data (without previously entered errors) will be served
                return(PartialView("WebsiteNamePartialView", UpdateSettingsNameViewModel()));
            }
            else // JS disabled - no partial updates available
            {
                // Refreshing the page will not cause re-post
                return(RedirectToAction("Index", UpdatePage()));
            }
        }
示例#2
0
        public SettingsNameViewModel UpdateSettingsNameViewModel()
        {
            SettingsNameViewModel model = new SettingsNameViewModel();

            try
            {
                model.WebsiteName = _dbHelper.GetWebsiteName();
                return(model);
            }
            catch
            {
                model.WebsiteName = string.Empty;
                return(model);
            };
        }