Ejemplo n.º 1
0
        public ActionResult Main()
        {
            var model = new AdministratorMainViewModel
            {
                PostedSolutionsRootFolder = ConfigurationManager.AppSettings["PostedSolutionsRootFolder"],
                SiteConfigFolder          = ConfigurationManager.AppSettings["SiteConfigFolder"],
                RecaptchaPrivateKey       = ConfigurationManager.AppSettings["recaptchaPrivateKey"],
                RecaptchaPublicKey        = ConfigurationManager.AppSettings["recaptchaPublicKey"]
            };

            if (bool.TryParse(ConfigurationManager.AppSettings["AllowRegister"], out var allowRegister))
            {
                model.AllowRegister = allowRegister;
                if (bool.TryParse(ConfigurationManager.AppSettings["AllowRegisterTeacher"], out var allowRegisterTeacher))
                {
                    model.AllowRegisterTeacher = allowRegisterTeacher;
                    if (bool.TryParse(ConfigurationManager.AppSettings["UseRecaptcha"], out var useRecaptcha))
                    {
                        model.UseRecaptcha = useRecaptcha;
                        return(View(model));
                    }
                }
                ModelState.AddModelError("", "Не удалось считать параметр приложения 'AllowRegisterTeacher'");
                model.AllowRegister = true;
                return(View(model));
            }
            ModelState.AddModelError("", "Не удалось считать параметр приложения 'AllowRegister'");
            model.AllowRegister = true;
            return(View(model));
        }
Ejemplo n.º 2
0
 public ActionResult Main(AdministratorMainViewModel model)
 {
     if (ModelState.IsValid)
     {
         ConfigurationManager.AppSettings.Set("PostedSolutionsRootFolder", model.PostedSolutionsRootFolder.ToLower());
         ConfigurationManager.AppSettings.Set("SiteConfigFolder", model.SiteConfigFolder.ToLower());
         ConfigurationManager.AppSettings.Set("AllowRegister", model.AllowRegister.ToString().ToLower());
         ConfigurationManager.AppSettings.Set("AllowRegisterTeacher", model.AllowRegisterTeacher.ToString().ToLower());
         ConfigurationManager.AppSettings.Set("useRecaptcha", model.UseRecaptcha.ToString().ToLower());
         ConfigurationManager.AppSettings.Set("recaptchaPrivateKey", model.RecaptchaPrivateKey);
         ConfigurationManager.AppSettings.Set("recaptchaPublicKey", model.RecaptchaPublicKey);
         TempData["Message"] = "Конфигурация была сохранена";
         return(RedirectToAction("Main"));
     }
     ModelState.AddModelError("", "Проверьте правильность введенных данных");
     return(RedirectToAction("Main"));
 }