public ActionResult Create(User user) { if (ModelState.IsValid) { var userController = new MoUserController(); var encryptedMd5Pas = Encryptor.MD5Hash(user.Password); user.Password = encryptedMd5Pas; user.GroupID = "admin"; long id = userController.Insert(user); if (id > 0) { SetAlert("Thêm user thành công", "success"); return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Thêm user không thành công"); } } return(View("Index")); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { var userController = new MoUserController(); if (userController.CheckUserName(model.UserName)) { ModelState.AddModelError("", "Invalid user name"); } else if (userController.CheckEmail(model.Email)) { ModelState.AddModelError("", "Email has already been registed"); } else { var user = new User(); user.Name = model.Name; user.Password = Encryptor.MD5Hash(model.Password); user.Phone = model.Phone; user.Address = model.Address; user.Email = model.Email; user.CreatedDate = DateTime.Now; user.Status = true; user.GroupID = "customer"; var result = userController.Insert(user); if (result > 0) { ViewBag.Success = "Registerd Success"; model = new RegisterModel(); } else { ModelState.AddModelError("", "Error occur"); } } } return(View(model)); }