示例#1
0
        public ActionResult Setup(SetupViewModel model) {
            HttpContext.Server.ScriptTimeout = 600;

            if (string.IsNullOrEmpty(model.DatabaseConnectionString))
                ModelState.AddModelError("DatabaseConnectionString", "链接字符串不能为空");

            if (!String.IsNullOrWhiteSpace(model.ConfirmPassword) && model.AdminPassword != model.ConfirmPassword) {
                ModelState.AddModelError("ConfirmPassword", "两次输入的密码不一致");
            }

            if (!String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) {
                model.DatabaseTablePrefix = model.DatabaseTablePrefix.Trim();
                if (!Char.IsLetter(model.DatabaseTablePrefix[0])) {
                    ModelState.AddModelError("DatabaseTablePrefix", "表前缀必须是英文字符");
                }

                if (model.DatabaseTablePrefix.Any(x => !Char.IsLetterOrDigit(x))) {
                    ModelState.AddModelError("DatabaseTablePrefix", "表前缀只能包含数字和英文字符");
                }
            }

            try {
                var setting = new SysSetting {
                    SiteName = model.SiteName,
                    DataProvider = model.DatabaseProvider,
                    DataConnectionString = model.DatabaseConnectionString,
                    DataTablePrefix = model.DatabaseTablePrefix,
                    State = TenantState.Running,
                    AdminUsername = model.AdminUsername,
                    AdminPassword = model.AdminPassword
                };

                _settingManager.Save(setting, _databaseSetup);
                _userSetup.Setup(setting);

                return Redirect("/");
            } catch (Exception ex) {
                Logger.Error("Error:{0}", ex);
                return IndexViewResult(model);
            }
        }
示例#2
0
 private ActionResult IndexViewResult(SetupViewModel model) {
     return View(model);
 }