private static void UpdateStaffGroups(StaffDetail detail, Staff staff, Predicate <StaffGroupSummary> p1, Predicate <StaffGroup> p2, IPersistenceContext context) { // create a helper to sync staff group membership CollectionSynchronizeHelper <StaffGroup, StaffGroupSummary> helper = new CollectionSynchronizeHelper <StaffGroup, StaffGroupSummary>( delegate(StaffGroup group, StaffGroupSummary summary) { return(group.GetRef().Equals(summary.StaffGroupRef, true)); }, delegate(StaffGroupSummary groupSummary, ICollection <StaffGroup> groups) { StaffGroup group = context.Load <StaffGroup>(groupSummary.StaffGroupRef, EntityLoadFlags.Proxy); group.AddMember(staff); }, delegate { // do nothing }, delegate(StaffGroup group, ICollection <StaffGroup> groups) { group.RemoveMember(staff); } ); helper.Synchronize( CollectionUtils.Select(staff.Groups, p2), CollectionUtils.Select(detail.Groups, p1)); }
public void UpdateStaffGroup(StaffGroup group, StaffGroupDetail detail, bool updateWorklist, bool isNewStaffGroup, IPersistenceContext context) { group.Name = detail.Name; group.Description = detail.Description; group.Elective = detail.IsElective; group.Deactivated = detail.Deactivated; group.Members.Clear(); CollectionUtils.ForEach(detail.Members, delegate(StaffSummary summary) { group.AddMember(context.Load <Staff>(summary.StaffRef, EntityLoadFlags.Proxy)); }); if (updateWorklist) { StaffGroupWorklistCollectionSynchronizeHelper helper = new StaffGroupWorklistCollectionSynchronizeHelper(group, context); IList <Worklist> originalWorklists = isNewStaffGroup ? new List <Worklist>() : context.GetBroker <IWorklistBroker>().Find(group); helper.Synchronize(originalWorklists, detail.Worklists); } }