public void UpdateStaff(StaffDetail detail, Staff staff, bool updateElectiveGroups, bool updateNonElectiveGroups, IPersistenceContext context) { PersonNameAssembler assembler = new PersonNameAssembler(); EmailAddressAssembler emailAssembler = new EmailAddressAssembler(); TelephoneNumberAssembler telephoneAssembler = new TelephoneNumberAssembler(); AddressAssembler addressAssembler = new AddressAssembler(); staff.Id = detail.StaffId; staff.Type = EnumUtils.GetEnumValue<StaffTypeEnum>(detail.StaffType, context); assembler.UpdatePersonName(detail.Name, staff.Name); staff.Sex = EnumUtils.GetEnumValue<Sex>(detail.Sex); staff.Title = detail.Title; staff.LicenseNumber = detail.LicenseNumber; staff.BillingNumber = detail.BillingNumber; staff.Deactivated = detail.Deactivated; staff.UserName = detail.UserName; staff.TelephoneNumbers.Clear(); if (detail.TelephoneNumbers != null) { foreach (TelephoneDetail phoneDetail in detail.TelephoneNumbers) { staff.TelephoneNumbers.Add(telephoneAssembler.CreateTelephoneNumber(phoneDetail)); } } staff.Addresses.Clear(); if (detail.Addresses != null) { foreach (AddressDetail addressDetail in detail.Addresses) { staff.Addresses.Add(addressAssembler.CreateAddress(addressDetail)); } } staff.EmailAddresses.Clear(); if (detail.EmailAddresses != null) { foreach (EmailAddressDetail emailAddressDetail in detail.EmailAddresses) { staff.EmailAddresses.Add(emailAssembler.CreateEmailAddress(emailAddressDetail)); } } ExtendedPropertyUtils.Update(staff.ExtendedProperties, detail.ExtendedProperties); if (updateElectiveGroups) { // update elective groups UpdateStaffGroups(detail, staff, delegate(StaffGroupSummary summary) { return summary.IsElective; }, delegate(StaffGroup group) { return group.Elective; }, context); } if (updateNonElectiveGroups) { // update non-elective groups UpdateStaffGroups(detail, staff, delegate(StaffGroupSummary summary) { return !summary.IsElective; }, delegate(StaffGroup group) { return !group.Elective; }, context); } }
/// <summary> /// Formats the staff name and role similar to "Test, Name (Role)" with the name formatted according to the specified format string. /// </summary> /// <remarks> /// Valid format specifiers are as follows: /// %F - full family name /// %f - family name initial /// %G - full given name /// %g - given name initial /// %M - full middle name /// %m - middle initial /// </remarks> /// <param name="staff"></param> /// <param name="format"></param> /// <returns></returns> public static string Format(StaffDetail staff, string format) { return string.Format("{0} ({1})", PersonNameFormat.Format(staff.Name, format), staff.StaffType.Value); }
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)); }
/// <summary> /// Formats the staff name and role similar to "Test, Name (Role)". Name is formatted according to the default person name format as /// specified in <see cref="FormatSettings"/> /// </summary> /// <param name="staff"></param> /// <returns></returns> public static string Format(StaffDetail staff) { return Format(staff, FormatSettings.Default.PersonNameDefaultFormat); }