public SysUser UpdateUserRoleByUserId(string userId, string roleIds) { string[] arr = roleIds.Split(','); var UpdateUser = m_Rep.Find(Convert.ToInt32(userId)); if (UpdateUser == null) { return(null); } else { UpdateUser.RoleName = string.Empty; } foreach (string roleid in arr) { if (!string.IsNullOrWhiteSpace(roleid)) { var role = _SysRoleRepository.Find(a => a.Id == Convert.ToInt32(roleid)); if (role != null) { UpdateUser.RoleName = UpdateUser.RoleName + role.Name; } } } return(UpdateUser); }
public bool UpdateRolesByUserId(string userId, string roleIds) { string[] arr = roleIds.Split(','); var UpdateUser = userRepository.Find(Convert.ToInt32(userId)); if (UpdateUser == null) { return(false); } else { UpdateUser.RoleName = string.Empty; var Roles = m_Rep.FindList(a => a.SysUserId == userId); if (Roles != null) { m_Rep.Delete(Roles); } } foreach (string roleid in arr) { if (!string.IsNullOrWhiteSpace(roleid)) { SysRoleSysUser Insert = new SysRoleSysUser(); Insert.SysRoleId = roleid; Insert.SysUserId = userId; var role = roleRepository.Find(Convert.ToInt32(roleid)); if (role != null) { UpdateUser.RoleName = UpdateUser.RoleName + "[" + role.Name + "]"; Insert.SysRoleName = role.Name; } m_Rep.Create(Insert); } } userRepository.Update(UpdateUser); return(true); }