public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { AdminBLL adminBLL = new AdminBLL(); tblAdmin admin = new tblAdmin() { username = model.UserName, password = model.Password }; //admin.username = model.UserName; //admin.password = model.Password; int effectedRow = adminBLL.addAdmin(admin); if (effectedRow == 1) { return RedirectToAction("index", "Home"); } else { ModelState.AddModelError("", "注册失败,用户名已被占用"); } //WebSecurity.CreateUserAndAccount(model.UserName, model.Password); //WebSecurity.Login(model.UserName, model.Password); //return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
// // GET: /Admin/ public ActionResult Index() { AdminBLL adminBLL = new AdminBLL(); ViewData["admins"] = adminBLL.getAllAdmins(); return View(); }
public ActionResult Login(LoginModel model, string returnUrl) { //if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) AdminBLL adminBLL = new AdminBLL(); var loginRet = adminBLL.loginIn(new tblAdmin(){username = model.UserName, password = model.Password}); if (ModelState.IsValid && (loginRet != null)) { return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "用户名或密码错误"); return View(model); }
public ActionResult Delete(int id) { AdminBLL adminBLL = new AdminBLL(); adminBLL.deleteAdmin(id); return RedirectToAction("Index"); }