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; } } }
/// <summary> /// 发送邮件 /// </summary> public void SendMail(string to, string cc, string subject, string body, MailPriority priority, params Guid[] files) { using (TranscationHelper trans = TranscationHelper.GetInstance()) { trans.BeginTrans(); try { SendMail(trans, to, cc, subject, body, priority, files); trans.CommitTrans(); } catch { trans.RollTrans(); throw; } } }
public void AddUser(User user) { if (user.UID == Guid.Empty) { user.UID = Guid.NewGuid(); } if (user.Organ == null) { throw new BusinessObjectLogicException("Invalid Organ!"); } //if (user.Superior == null) throw new BusinessObjectLogicException("Invalid Manager!"); user.CreateTime = DateTime.Now; user.Password = RandomString.GetPassword(); using (TranscationHelper trans = TranscationHelper.GetInstance()) { trans.BeginTrans(); try { UserDa.InsertUser(user, trans); foreach (UserRole role in user.Roles) { UserDa.InsertUserRole(role, trans); } trans.CommitTrans(); } catch { trans.RollTrans(); throw; } } if (user.Superior == null) // 更新为自己 { user.Superior = new UserBase(user.ItCode); UserDa.UpdateUser(user); } }
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; } } }