public EditViewModel(int id) { var sysStaffUser = CurrentDb.SysStaffUser.Where(m => m.Id == id).FirstOrDefault(); if (sysStaffUser != null) { _sysStaffUser = sysStaffUser; } }
public CustomJsonResult Edit(EditViewModel model) { var user = new SysStaffUser(); user.Id = model.SysStaffUser.Id; user.Password = model.SysStaffUser.Password; user.FullName = model.SysStaffUser.FullName; user.Email = model.SysStaffUser.Email; user.PhoneNumber = model.SysStaffUser.PhoneNumber; int[] userRoleIds = model.UserRoleIds; return(SysFactory.AuthorizeRelay.UpdateUser <SysStaffUser>(this.CurrentUserId, user, userRoleIds)); }
private StaffUserModel GetStaffUserModel(int userId) { StaffUserModel model = new StaffUserModel(); SysStaffUser user = CurrentDb.SysStaffUser.Where(m => m.Id == userId).FirstOrDefault(); model.Id = user.Id; model.UserName = user.UserName; model.PhoneNumber = user.PhoneNumber; model.Email = user.Email; model.FirstName = user.FirstName; model.LastName = user.LastName; return(model); }
public CustomJsonResult Add(AddViewModel model) { var user = new SysStaffUser(); user.UserName = string.Format("HYL{0}", model.SysStaffUser.UserName); user.FullName = model.SysStaffUser.FullName; user.PasswordHash = PassWordHelper.HashPassword(model.SysStaffUser.Password); user.Email = model.SysStaffUser.Email; user.PhoneNumber = model.SysStaffUser.PhoneNumber; user.Type = Enumeration.UserType.Staff; user.IsDelete = false; user.Status = Enumeration.UserStatus.Normal; int[] userRoleIds = model.UserRoleIds; return(SysFactory.AuthorizeRelay.CreateUser <SysStaffUser>(this.CurrentUserId, user, userRoleIds)); }
public JsonResult Edit(EditViewModel model) { var identiy = new AspNetIdentiyAuthorizeRelay <SysStaffUser>(); SysStaffUser user = identiy.GetUser(model.SysStaffUser.Id); user.FullName = model.SysStaffUser.FullName; user.Email = model.SysStaffUser.Email; user.PhoneNumber = model.SysStaffUser.PhoneNumber; user.Mender = this.CurrentUserId; user.LastUpdateTime = DateTime.Now; int[] userRoleIds = model.UserRoleIds; bool r = identiy.UpdateUser(this.CurrentUserId, user, model.SysStaffUser.PasswordHash, model.UserRoleIds); if (!r) { return(Json(ResultType.Failure, WebBackOperateTipUtils.UPDATE_FAILURE)); } return(Json(ResultType.Success, WebBackOperateTipUtils.UPDATE_SUCCESS)); }
public JsonResult Add(StaffUserModel model) { SysStaffUser user = new SysStaffUser(); user.UserName = model.UserName; // user.FullName = model.FullName; user.FirstName = model.FirstName; user.LastName = model.LastName; user.PasswordHash = model.Password; user.Email = model.Email; user.PhoneNumber = model.PhoneNumber; user.IsModifyPwd = false; user.IsDelete = false; user.IsDisable = false; user.Creator = User.Identity.GetUserId <int>(); user.CreateTime = DateTime.Now; int[] userRoleIds = model.UserRoleIds; var identiy = new AspNetIdentiyAuthorizeRelay <SysStaffUser>(CurrentDb); if (identiy.UserExists(user.UserName.Trim())) { return(Json(ResultType.Failure, ManagerOperateTipUtils.USER_EXISTS)); } bool r = identiy.CreateUser(user, model.UserRoleIds); if (!r) { return(Json(ResultType.Failure, ManagerOperateTipUtils.ADD_FAILURE)); } return(Json(ResultType.Success, ManagerOperateTipUtils.ADD_SUCCESS)); }
public JsonResult Update(StaffUserModel model) { var identiy = new AspNetIdentiyAuthorizeRelay <SysStaffUser>(CurrentDb); SysStaffUser user = identiy.GetUser(model.Id); //user.FullName = model.FullName; user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; user.PhoneNumber = model.PhoneNumber; user.Mender = User.Identity.GetUserId <int>(); user.LastUpdateTime = DateTime.Now; int[] userRoleIds = model.UserRoleIds; bool r = identiy.UpdateUser(user, model.Password, model.UserRoleIds); if (!r) { return(Json(ResultType.Failure, ManagerOperateTipUtils.UPDATE_FAILURE)); } return(Json(ResultType.Success, ManagerOperateTipUtils.UPDATE_SUCCESS)); }
public JsonResult Add(AddViewModel model) { SysStaffUser user = new SysStaffUser(); user.UserName = model.SysStaffUser.UserName; user.FullName = model.SysStaffUser.FullName; user.PasswordHash = model.SysStaffUser.PasswordHash; user.Email = model.SysStaffUser.Email; user.IsModifyDefaultPwd = false; user.IsDelete = false; user.Status = Enumeration.UserStatus.Normal; user.Creator = this.CurrentUserId; user.CreateTime = DateTime.Now; int[] userRoleIds = model.UserRoleIds; var identiy = new AspNetIdentiyAuthorizeRelay <SysStaffUser>(); if (identiy.UserExists(user.UserName.Trim())) { return(Json(ResultType.Failure, WebBackOperateTipUtils.USER_EXISTS)); } bool r = identiy.CreateUser(this.CurrentUserId, user, model.UserRoleIds); if (!r) { return(Json(ResultType.Failure, WebBackOperateTipUtils.ADD_FAILURE)); } return(Json(ResultType.Success, WebBackOperateTipUtils.ADD_SUCCESS)); }
public CustomJsonResult Add(string pOperater, RopSysStaffUserAdd rop) { CustomJsonResult result = new CustomJsonResult(); var isExistUserName = CurrentDb.SysUser.Where(m => m.UserName == rop.UserName).FirstOrDefault(); if (isExistUserName != null) { return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("该用户名({0})已被使用", rop.UserName))); } using (TransactionScope ts = new TransactionScope()) { var sysStaffUser = new SysStaffUser(); sysStaffUser.Id = GuidUtil.New(); sysStaffUser.UserName = string.Format("Up{0}", rop.UserName); sysStaffUser.FullName = rop.FullName; sysStaffUser.PasswordHash = PassWordHelper.HashPassword(rop.Password); sysStaffUser.Email = rop.Email; sysStaffUser.PhoneNumber = rop.PhoneNumber; sysStaffUser.Type = Enumeration.UserType.Staff; sysStaffUser.IsDelete = false; sysStaffUser.IsCanDelete = true; sysStaffUser.Status = Enumeration.UserStatus.Normal; sysStaffUser.Creator = pOperater; sysStaffUser.CreateTime = DateTime.Now; sysStaffUser.RegisterTime = DateTime.Now; sysStaffUser.Status = Enumeration.UserStatus.Normal; sysStaffUser.SecurityStamp = Guid.NewGuid().ToString().Replace("-", ""); CurrentDb.SysStaffUser.Add(sysStaffUser); CurrentDb.SaveChanges(); List <SysUserRole> userRoleList = CurrentDb.SysUserRole.Where(m => m.UserId == sysStaffUser.Id).ToList(); foreach (var userRole in userRoleList) { CurrentDb.SysUserRole.Remove(userRole); } if (rop.RoleIds != null) { if (rop.RoleIds.Length > 0) { foreach (string roleId in rop.RoleIds) { CurrentDb.SysUserRole.Add(new SysUserRole { Id = GuidUtil.New(), UserId = sysStaffUser.Id, RoleId = roleId, Creator = pOperater, CreateTime = DateTime.Now, IsCanDelete = true }); } } } result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "新建成功"); CurrentDb.SaveChanges(); ts.Complete(); } return(result); }