public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { if (!WebSecurity.UserExists(model.UserName)) { AddNewAccount(model); ViewBag.StatusMessage = "Tạo tài khoản thành công."; } else ViewBag.StatusMessage = "Email này đã được sử dụng bởi nhân viên khác."; } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } PersonService pservice = new PersonService(); model.ListOfPersonName = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, null, null).ToList(); // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register() { RegisterModel model = new RegisterModel(); PersonService pservice = new PersonService(); //model.ListOfPersonName = pservice.GetListOnWorkingOfPersonName(System.DateTime.Now, null, null).ToList(); return View(model); }
public ActionResult Index() { RegisterModel model = new RegisterModel(); PersonService pservice = new PersonService(); DepartmentService departmentService = new DepartmentService(); //model.ListOfPersonName = pservice.GetListOnWorkingOfPersonName(System.DateTime.Now, null, null).ToList(); model.Departments = departmentService.GetAll().ToList(); model.ListOfPersonName = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, null, null).ToList(); return View(model); }
public JsonResult CreateNewAccount(string username, string password, bool view1Role, bool view2Role, bool view3Role, bool editRole, bool deleteRole, bool adminRole, int personId) { string result = string.Empty; try { if (username != null && !username.Trim().Equals(string.Empty) && !WebSecurity.UserExists(username)) { RegisterModel model = new RegisterModel() { UserName = username, Password = password, View1Role = view1Role, View2Role = view2Role, View3Role = view3Role, EditRole = editRole, DeleteRole = deleteRole, AdminRole = adminRole, PersonId = personId }; AddNewAccount(model); } else result = "Username này đã được sử dụng bởi nhân viên khác."; } catch (Exception ex) { result = "Lỗi: " + ex.Message; } return Json(result); }
public JsonResult CreateAccountAutomatic(string password) { string result = string.Empty; PersonService pservice = new PersonService(); try { foreach (Person p in pservice.GetAll()) { if (p.Email != null && !p.Email.Trim().Equals(string.Empty) && !WebSecurity.UserExists(p.Email.Trim())) { RegisterModel model = new RegisterModel() { UserName = p.Email, Password = password, View1Role = true, View2Role = false, View3Role = false, EditRole = false, DeleteRole = false, AdminRole = false, PersonId = p.Id }; AddNewAccount(model); } } } catch (Exception ex) { result = "Lỗi: " + ex.Message; } return Json(result); }
private string AddNewAccount(RegisterModel model) { string result = string.Empty; if (!WebSecurity.UserExists(model.UserName)) { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); if (model.View1Role) { RoleAddToUser(RoleNames.view1Role, model.UserName); } if (model.View2Role) { RoleAddToUser(RoleNames.view2Role, model.UserName); } if (model.View3Role) { RoleAddToUser(RoleNames.view3Role, model.UserName); } if (model.EditRole) { RoleAddToUser(RoleNames.editRole, model.UserName); } if (model.DeleteRole) { RoleAddToUser(RoleNames.deleteRole, model.UserName); } if (model.AdminRole) { RoleAddToUser(RoleNames.adminRole, model.UserName); } PersonAccount pa = new PersonAccount() { UserId = WebSecurity.GetUserId(model.UserName), Person = unitOfWork.PersonRepository.GetByID(model.PersonId) }; unitOfWork.PersonAccountRepository.Insert(pa); unitOfWork.Save(); } else result = "User này đã có trong cơ sở dữ liệu rồi."; return result; }