public User GetUserByItCodeWithRole(string itcode) { User user = UserDa.GetUserByItCode(itcode); user.Roles.AddRange(UserDa.GetUserRole(user.ItCode, null, null)); return(user); }
public void EditUserRole(string itcode, string bu, List <UserRole> roles) { List <UserRole> existRoles = UserDa.GetUserRole(itcode, null, bu); List <UserRole> rolesAdd = new List <UserRole>(); List <UserRole> rolesDel = new List <UserRole>(); //foreach (UserRole role in existRoles) //{ // if (!roles.Exists(r => (r.Role == role.Role && r.BU == role.BU))) // rolesDel.Add(role); // //if (!user.Roles.Exists(delegate(UserRole r) { return r.Role == role.Role && r.BU == role.BU; })) // //{ } //} //foreach (UserRole role in roles) //{ // if (!existRoles.Exists(r => (r.Role == role.Role && r.BU == role.BU))) // rolesAdd.Add(role); //} // 如果没有实际更改 if (rolesAdd.Count == 0 && rolesDel.Count == 0) { return; } using (TranscationHelper trans = TranscationHelper.GetInstance()) { trans.BeginTrans(); try { foreach (UserRole role in rolesDel) { UserDa.DeleteUserRole(role, trans); } foreach (UserRole role in rolesAdd) { UserDa.InsertUserRole(role, trans); } trans.CommitTrans(); } catch { trans.RollTrans(); throw; } } }
public List <UserRole> GetUserRole(string user, string bu) { return(UserDa.GetUserRole(user, null, bu)); }
public void EditUser(User user) { User existUser = UserDa.GetUserByItCode(user.ItCode); existUser.Roles.AddRange(UserDa.GetUserRole(existUser.ItCode, null, null)); if (user == null) { throw new BusinessObjectLogicException("Invalid User!"); } if (user.Organ == null) { throw new BusinessObjectLogicException("Invalid Organ!"); } if (user.Superior == null) { throw new BusinessObjectLogicException("Invalid Manager!"); } if (user.Disabled && existUser.Disabled) { throw new BusinessObjectLogicException("User is disabled!"); } bool updateUser = false; if (existUser.FirstName != user.FirstName || existUser.LastName != user.LastName || existUser.AbbrName != user.AbbrName || existUser.Organ.ID != user.Organ.ID || existUser.Superior.ItCode != user.Superior.ItCode || existUser.Phone != user.Phone || existUser.Disabled != user.Disabled || existUser.Department != user.Department) { existUser.FirstName = user.FirstName; existUser.LastName = user.LastName; existUser.AbbrName = user.AbbrName; existUser.Organ = user.Organ; existUser.Superior = user.Superior; existUser.Phone = user.Phone; existUser.Disabled = user.Disabled; existUser.Department = user.Department; updateUser = true; } List <UserRole> rolesAdd = new List <UserRole>(); List <UserRole> rolesDel = new List <UserRole>(); //foreach (UserRole role in existUser.Roles) //{ // if (!user.Roles.Exists(r => (r.Role == role.Role && r.BU == role.BU))) // rolesDel.Add(role); // //if (!user.Roles.Exists(delegate(UserRole r) { return r.Role == role.Role && r.BU == role.BU; })) // //{ } //} //foreach (UserRole role in user.Roles) //{ // if (!existUser.Roles.Exists(r => (r.Role == role.Role && r.BU == role.BU))) // rolesAdd.Add(role); //} // 如果没有实际更改 if (!updateUser && rolesAdd.Count == 0 && rolesDel.Count == 0) { return; } using (TranscationHelper trans = TranscationHelper.GetInstance()) { trans.BeginTrans(); try { if (updateUser) { UserDa.UpdateUser(existUser, trans); } foreach (UserRole role in rolesDel) { UserDa.DeleteUserRole(role, trans); } foreach (UserRole role in rolesAdd) { UserDa.InsertUserRole(role, trans); } trans.CommitTrans(); } catch { trans.RollTrans(); throw; } } }