public object PostAddEdit(DepartmentMemberAddEditDTO departmentMemberVM) { departmentMemberVM.Roles = base.MyRequest.Form["Roles"].ToStringObj().Split(',').Select(c => new QueryModel(c.ToString(), "")).ToList(); ResultOperation resultOperation = new ResultOperation(); using (DepartmentMemberService departmentMemberService = new DepartmentMemberService()) { List <sysBpmsDepartmentMember> list = departmentMemberService.GetList(departmentMemberVM.DepartmentID, null, departmentMemberVM.UserID); foreach (var item in list.Where(c => !departmentMemberVM.Roles.Select(d => d.Key).Contains(c.RoleLU.ToString()))) { if (resultOperation.IsSuccess) { resultOperation = departmentMemberService.Delete(item.ID); } } foreach (var item in departmentMemberVM.Roles.Where(c => !list.Any(d => d.RoleLU == c.Key.ToIntObj()))) { if (resultOperation.IsSuccess) { sysBpmsDepartmentMember newMember = new sysBpmsDepartmentMember(); newMember.Update(departmentMemberVM.DepartmentID, departmentMemberVM.UserID, item.Key.ToIntObj()); resultOperation = departmentMemberService.Add(newMember); } } } if (resultOperation.IsSuccess) { return(new PostMethodMessage(SharedLang.Get("Success.Text"), DisplayMessageType.success)); } else { return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error)); } }
public bool AddRoleToUser(Guid userID, Guid departmentID, int roleCode) { DepartmentMemberService departmentMemberService = new DepartmentMemberService(this.UnitOfWork); if (departmentMemberService.GetList(departmentID, roleCode, userID).Count == 0) { sysBpmsDepartmentMember sysBpmsDepartmentMember = new sysBpmsDepartmentMember(); sysBpmsDepartmentMember.Update(departmentID, userID, roleCode); departmentMemberService.Add(sysBpmsDepartmentMember); } return(true); }