/// <summary> /// Initializes a new instance of the <see cref="NidaDrugQuestionnaireViewModel"/> class. /// </summary> /// <param name="userDialogService">The user dialog service.</param> /// <param name="asyncRequestDispatcherFactory">The async request dispatcher factory.</param> /// <param name="accessControlManager">The access control manager.</param> /// <param name="eventAggregator">The event aggregator.</param> /// <param name="commandFactory">The command factory.</param> public NidaDrugQuestionnaireViewModel( IUserDialogService userDialogService, IAsyncRequestDispatcherFactory asyncRequestDispatcherFactory, IAccessControlManager accessControlManager, IEventAggregator eventAggregator, ICommandFactory commandFactory) : base(userDialogService, asyncRequestDispatcherFactory, accessControlManager, eventAggregator, commandFactory) { _eventAggregator = eventAggregator; _asyncRequestDispatcherFactory = asyncRequestDispatcherFactory; _userDialogService = userDialogService; var commandFactoryHelper = CommandFactoryHelper.CreateHelper(this, commandFactory); SaveCommand = commandFactoryHelper.BuildDelegateCommand <KeyedDataTransferObject> ( () => SaveCommand, dto => { var name = PropertyUtil.ExtractPropertyName(() => EditingDto); if (dto != null && EditingDto.GetType() != dto.GetType()) { name = EditingDto.GetType().GetProperties().First(pi => pi.PropertyType == dto.GetType()).Name; } return(name); }, ExecuteSaveCommand, CanExecuteSaveCommand); var ruleExecutor = new NotifyPropertyChangedRuleExecutor <NidaDrugQuestionnaireViewModel, IDataTransferObject> (); ruleExecutor.AddRunAllRulesProperty(vm => vm.EditingDto); ruleExecutor.WatchSubject(this); }
/// <summary> /// Initializes a new instance of the <see cref="ProgramOfferingEditorViewModel"/> class. /// </summary> /// <param name="userDialogService">The user dialog service.</param> /// <param name="asyncRequestDispatcherFactory">The async request dispatcher factory.</param> /// <param name="accessControlManager">The access control manager.</param> /// <param name="commandFactory">The command factory.</param> /// <param name="popupService">The popup service.</param> public ProgramOfferingEditorViewModel( IUserDialogService userDialogService, IAsyncRequestDispatcherFactory asyncRequestDispatcherFactory, IAccessControlManager accessControlManager, ICommandFactory commandFactory, IPopupService popupService) : base(userDialogService, asyncRequestDispatcherFactory, accessControlManager, commandFactory) { _userDialogService = userDialogService; _asyncRequestDispatcherFactory = asyncRequestDispatcherFactory; _popupService = popupService; CreateCommand = NavigationCommandManager.BuildCommand(() => CreateCommand, NavigateToCreateCommand); EditCommand = NavigationCommandManager.BuildCommand(() => EditCommand, NavigateToEditCommand); var commandFactoryHelper = CommandFactoryHelper.CreateHelper(this, commandFactory); SaveCommand = commandFactoryHelper.BuildDelegateCommand <KeyedDataTransferObject> ( () => SaveCommand, dto => { var name = PropertyUtil.ExtractPropertyName(() => EditingDto); if (dto != null && EditingDto.GetType() != dto.GetType()) { name = EditingDto.GetType().GetProperties().First(pi => pi.PropertyType == dto.GetType()).Name; } return(name); }, ExecuteSaveCommand, CanExecuteSaveCommand); }
/// <summary> /// Updates the dto read only. /// </summary> protected void UpdateDtoReadOnly() { if (EditingDto != null && VisitStatusWellKnownName != null) { if (VisitStatusWellKnownName == VisitStatus.CheckedIn) { EditingDto.IsNotReadOnly(); } else { EditingDto.IsReadOnly(); } } }
/// <summary> /// Requests the completed. /// </summary> /// <param name="receivedResponses">The received responses.</param> protected virtual void RequestCompleted(ReceivedResponses receivedResponses) { _editingPart.IsLoading = false; var response = receivedResponses.Responses.ElementAt(0) as IDtoResponse; var responseDtoType = response.GetType().GetGenericArguments().ElementAt(0); if (responseDtoType == EditingDto.GetType()) { EditingDto = response.GetDto() as TDto; } else { foreach (var propInfo in EditingDto.GetType().GetProperties()) { if (propInfo.PropertyType == responseDtoType) { propInfo.SetValue( EditingDto, response.GetDto(), BindingFlags.SetProperty, null, null, Thread.CurrentThread.CurrentCulture); break; } } } }
/// <summary> /// Requests the completed. /// </summary> /// <param name="receivedResponses">The received responses.</param> protected override void RequestCompleted(ReceivedResponses receivedResponses) { IsLoading = false; base.RequestCompleted(receivedResponses); if (EditingDto.HasErrors) { var errors = EditingDto.GetErrors(null); var errorMessageSb = new StringBuilder(); foreach (DataErrorInfo dataErrorInfo in errors) { errorMessageSb.AppendLine(dataErrorInfo.ToString()); } errors = EditingDto.GetErrors(PropertyUtil.ExtractPropertyName <MailAttachmentPatientDocumentDto, object> (p => p.PatientDocumentType)); foreach (DataErrorInfo dataErrorInfo in errors) { errorMessageSb.AppendLine(dataErrorInfo.ToString()); } errors = EditingDto.GetErrors( PropertyUtil.ExtractPropertyName <MailAttachmentPatientDocumentDto, object> (p => p.OtherDocumentTypeName)); foreach (DataErrorInfo dataErrorInfo in errors) { errorMessageSb.AppendLine(dataErrorInfo.ToString()); } errors = EditingDto.GetErrors(PropertyUtil.ExtractPropertyName <MailAttachmentPatientDocumentDto, object> (p => p.Description)); foreach (DataErrorInfo dataErrorInfo in errors) { errorMessageSb.AppendLine(dataErrorInfo.ToString()); } errors = EditingDto.GetErrors(PropertyUtil.ExtractPropertyName <MailAttachmentPatientDocumentDto, object> (p => p.ClinicalStartDate)); foreach (DataErrorInfo dataErrorInfo in errors) { errorMessageSb.AppendLine(dataErrorInfo.ToString()); } errors = EditingDto.GetErrors( PropertyUtil.ExtractPropertyName <MailAttachmentPatientDocumentDto, object> (p => p.ClinicalEndDate)); foreach (DataErrorInfo dataErrorInfo in errors) { errorMessageSb.AppendLine(dataErrorInfo.ToString()); } errors = EditingDto.GetErrors( PropertyUtil.ExtractPropertyName <MailAttachmentPatientDocumentDto, object> (p => p.DocumentProviderName)); foreach (DataErrorInfo dataErrorInfo in errors) { errorMessageSb.AppendLine(dataErrorInfo.ToString()); } var errorMessage = errorMessageSb.ToString(); if (!string.IsNullOrWhiteSpace(errorMessage)) { _userDialogService.ShowDialog(errorMessage, "Save Mail Attachment to External Patient History", UserDialogServiceOptions.Ok); } } else { var patientDocumentUploadedEvent = new PatientDocumentUploadedEventArgs { PatientKey = EditingDto.PatientKey }; _eventAggregator.GetEvent <PatientDocumentUploadedEvent> ().Publish(patientDocumentUploadedEvent); _navigationService.Navigate( WorkspacesRegion, PatientWorkspaceView, "SubViewPassThrough", new[] { new KeyValuePair <string, string> ("PatientKey", Patient.Key.ToString()), new KeyValuePair <string, string> ("FullName", Patient.FullName), new KeyValuePair <string, string> ("SubViewName", ExternalPatientHistoryView) }); CloseViewCommand.Execute(null); } }