public ActionResult SignUpAdmin(AdminModel model) { if (ModelState.IsValid) { var adminDao = new AdminDAO(); if (adminDao.CheckUserName(model.Username)) { ModelState.AddModelError("", "This account has already existed."); } else if (adminDao.CheckEmail(model.Email)) { ModelState.AddModelError("", "This email has already existed."); } else if (adminDao.CheckPhoneNumber(model.PhoneNumber)) { ModelState.AddModelError("", "This phone number has already existed."); } else { adminDao.insertAccount(model); adminDao.insertAdmin(model); string message = "Sign up successfully."; return(RedirectToAction("AdminHome", "Admin", new { message })); } } return(View(model)); }
public ActionResult Register(AdminModel model) { if (ModelState.IsValid) { var dao = new AdminDAO(); if (dao.CheckUserName(model.Username)) { //ModelState.AddModelError("", "UserName already exists."); ViewBag.Error = "Username already exists."; } else { var admin = new Administrator(); admin.Username = model.Username; admin.Password = Encryptor.MD5Hash(model.Password); admin.FullName = model.FullName; admin.Role = model.Role = "Manager"; admin.Email = model.Email; admin.Phone = model.Phone; var result = dao.Insert(admin); if (result > 0) { ViewBag.Success = "Register Successful."; model = new AdminModel(); return(RedirectToAction("Index", "MManager")); } else { ModelState.AddModelError("", "Register Fail"); } } return(View(model)); } return(RedirectToAction("Login", "HomeAdmin")); }