/// <summary> /// Called to handle the "edit" action. /// </summary> /// <param name="items">A list of items to edit.</param> /// <param name="editedItems">The list of items that were edited.</param> /// <returns>True if items were edited, false otherwise.</returns> protected override bool EditItems(IList <ExternalPractitionerContactPointDetail> items, out IList <ExternalPractitionerContactPointDetail> editedItems) { editedItems = new List <ExternalPractitionerContactPointDetail>(); var item = CollectionUtils.FirstElement(items); var contactPoint = (ExternalPractitionerContactPointDetail)item.Clone(); // Keep looping until user enters an unique contact point name, or cancel the edit operation ApplicationComponentExitCode exitCode; while (true) { var editor = new ExternalPractitionerContactPointEditorComponent( contactPoint, _addressTypeChoices, _phoneTypeChoices, _resultCommunicationModeChoices, _informationAuthorityChoices); exitCode = LaunchAsDialog( this.Host.DesktopWindow, editor, string.Format(SR.TitleUpdateContactPoint + " - " + _practitionerName, contactPoint.Name)); var isUnique = IsContactPointNameUnique(item, contactPoint); if (exitCode == ApplicationComponentExitCode.Accepted && !isUnique) { this.Host.DesktopWindow.ShowMessageBox(string.Format(SR.MessageExternalPractitionerContactPointNotUnique, contactPoint.Name), MessageBoxActions.Ok); } else { break; } } if (exitCode == ApplicationComponentExitCode.Accepted) { editedItems.Add(contactPoint); // For new contact point, the updated contactPoint is a cloned of the original item. So they are not referenced equal. // There is also no entityRef. The only identifier is their name. // If name is changed, the IsSameItem won't identify the updated "contactPoint" and the original "item" as the same item // Therefore we must manually remove existing item and add updated contact point. var index = this.Table.Items.IndexOf(item); this.Table.Items.Remove(item); this.Table.Items.Insert(index, contactPoint); // if item was made default, then make sure no other items are also set as default if (contactPoint.IsDefaultContactPoint) { this.Table.MakeDefaultContactPoint(contactPoint); } return(true); } return(false); }
/// <summary> /// Called to handle the "add" action. /// </summary> /// <param name="addedItems"></param> /// <returns>True if items were added, false otherwise.</returns> protected override bool AddItems(out IList <ExternalPractitionerContactPointDetail> addedItems) { addedItems = new List <ExternalPractitionerContactPointDetail>(); var contactPoint = new ExternalPractitionerContactPointDetail { PreferredResultCommunicationMode = _resultCommunicationModeChoices.Count > 0 ? _resultCommunicationModeChoices[0] : null }; // Keep looping until user enters an unique contact point name, or cancel the add operation ApplicationComponentExitCode exitCode; while (true) { var editor = new ExternalPractitionerContactPointEditorComponent( contactPoint, _addressTypeChoices, _phoneTypeChoices, _resultCommunicationModeChoices, _informationAuthorityChoices); exitCode = LaunchAsDialog( this.Host.DesktopWindow, editor, SR.TitleAddContactPoint + " - " + _practitionerName); var isUnique = IsContactPointNameUnique(null, contactPoint); if (exitCode == ApplicationComponentExitCode.Accepted && !isUnique) { this.Host.DesktopWindow.ShowMessageBox(string.Format(SR.MessageExternalPractitionerContactPointNotUnique, contactPoint.Name), MessageBoxActions.Ok); } else { break; } } if (exitCode == ApplicationComponentExitCode.Accepted) { addedItems.Add(contactPoint); // if item was made default, then make sure no other items are also set as default if (contactPoint.IsDefaultContactPoint) { this.Table.MakeDefaultContactPoint(contactPoint); } return(true); } return(false); }