public ActionResult Create(Staff staff) { try { TryUpdateModel <Staff>(staff); IStaffService service = IoC.Resolve <IStaffService>(); service.CreateNew(staff); service.CommitChanges(); return(RedirectToAction("StaffIndex")); } catch (Exception e) { return(View()); } }
public ActionResult New(user temp, string RetypePassword, string[] UserRoles, string fullname) { IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); if (string.IsNullOrWhiteSpace(temp.username)) { AccountModel model = new AccountModel(); Messages.AddErrorMessage("Cần nhập những thông tin bắt buộc."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } try { if (temp.password != RetypePassword) { AccountModel model = new AccountModel(); Messages.AddErrorMessage(Resources.Message.User_MesConfirmPass); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } //Tao tai khoan string status = ""; Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; user u = _MemberShipProvider.CreateUser(temp.username, temp.password, temp.email, null, null, temp.IsApproved, null, currentCom.id.ToString(), out status); if (status != "Success") { AccountModel model = new AccountModel(); Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } _RoleProvider.UpdateUsersToRoles(u.userid, UserRoles); Messages.AddFlashMessage(Resources.Message.User_UMesSuccess); log.Info("Create Account:" + HttpContext.User.Identity.Name + ", Date: " + DateTime.Now); Company currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany; IStaffService _staSrv = IoC.Resolve <IStaffService>(); Staff newStaff = new Staff { FullName = fullname, AccountName = u.username, ComID = currentComp.id, Email = u.email }; _staSrv.CreateNew(newStaff); _staSrv.CommitChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error("Create Error:", ex); AccountModel model = new AccountModel(); Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); if (lst.IndexOf("ServiceRole") >= 0) { lst.RemoveAt(lst.IndexOf("ServiceRole")); } if (lst.IndexOf("Root") >= 0) { lst.RemoveAt(lst.IndexOf("Root")); } model.RetypePassword = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.UserTmp = temp; return(View("Create", model)); } }