public AppointmentViewModelBuilder(IViewModelCommunication viewModelCommunication,
                                    IClientLabelRepository labelRepository,
                                    ICommandService commandService,
                                    ISharedState <ViewModels.AppointmentView.Helper.AppointmentModifications> appointmentModificationsVariable,
                                    ISharedState <Date> selectedDateVariable,
                                    AdornerControl adornerControl,
                                    IAppointmentModificationsBuilder appointmentModificationsBuilder)
 {
     this.viewModelCommunication           = viewModelCommunication;
     this.labelRepository                  = labelRepository;
     this.commandService                   = commandService;
     this.appointmentModificationsVariable = appointmentModificationsVariable;
     this.selectedDateVariable             = selectedDateVariable;
     this.adornerControl                   = adornerControl;
     this.appointmentModificationsBuilder  = appointmentModificationsBuilder;
 }
Esempio n. 2
0
        public AppointmentViewModel(Appointment appointment,
                                    ICommandService commandService,
                                    IViewModelCommunication viewModelCommunication,
                                    TherapyPlaceRowIdentifier initialLocalisation,
                                    ISharedState <AppointmentModifications> appointmentModificationsVariable,
                                    ISharedState <Date> selectedDateVariable,
                                    IAppointmentModificationsBuilder appointmentModificationsBuilder,
                                    IWindowBuilder <EditDescription> editDescriptionWindowBuilder,
                                    AdornerControl adornerControl,
                                    Action <string> errorCallback)
        {
            this.appointment         = appointment;
            this.initialLocalisation = initialLocalisation;
            this.appointmentModificationsVariable = appointmentModificationsVariable;
            this.selectedDateVariable             = selectedDateVariable;
            ViewModelCommunication = viewModelCommunication;
            AdornerControl         = adornerControl;

            viewModelCommunication.RegisterViewModelAtCollection <IAppointmentViewModel, Guid>(
                Constants.ViewModelCollections.AppointmentViewModelCollection,
                this
                );

            SwitchToEditMode = new ParameterrizedCommand <bool>(
                isInitalAdjusting =>
            {
                if (appointmentModificationsVariable.Value == null)
                {
                    CurrentAppointmentModifications = appointmentModificationsBuilder.Build(appointment,
                                                                                            initialLocalisation.PlaceAndDate.MedicalPracticeId,
                                                                                            isInitalAdjusting,
                                                                                            errorCallback);

                    CurrentAppointmentModifications.PropertyChanged += OnAppointmentModificationsPropertyChanged;
                    appointmentModificationsVariable.Value           = CurrentAppointmentModifications;
                    OperatingMode = OperatingMode.Edit;
                    appointmentModificationsVariable.StateChanged += OnCurrentModifiedAppointmentChanged;
                }
            }
                );

            DeleteAppointment = new Command(
                async() =>
            {
                var dialog = new UserDialogBox("", "Wollen Sie den Termin wirklich löschen?",
                                               MessageBoxButton.OKCancel);
                var result = await dialog.ShowMahAppsDialog();

                if (result == MessageDialogResult.Affirmative)
                {
                    if (appointmentModificationsVariable.Value.IsInitialAdjustment)
                    {
                        viewModelCommunication.SendTo(                                                                                  //
                            Constants.ViewModelCollections.AppointmentViewModelCollection,                                              // do nothing but
                            appointmentModificationsVariable.Value.OriginalAppointment.Id,                                              // deleting the temporarly
                            new Dispose()                                                                                               // created Appointment
                            );                                                                                                          //
                    }
                    else
                    {
                        commandService.TryDeleteAppointment(
                            operationSuccessful =>
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                if (!operationSuccessful)
                                {
                                    Process(new RestoreOriginalValues());
                                    viewModelCommunication.Send(new ShowNotification("löschen des Termins fehlgeschlagen; bearbeitung wurde zurückgesetzt", 5));
                                }
                            });
                        },
                            currentLocation.PlaceAndDate,
                            appointment.Patient.Id,
                            appointment.Id,
                            appointment.Description,
                            appointment.StartTime,
                            appointment.EndTime,
                            appointment.TherapyPlace.Id,
                            appointment.Label.Id,
                            ActionTag.RegularAction,
                            errorCallback
                            );
                    }

                    appointmentModificationsVariable.Value = null;
                }
            }
                );

            EditDescription = new Command(
                () =>
            {
                viewModelCommunication.Send(new ShowDisabledOverlay());

                var dialog = editDescriptionWindowBuilder.BuildWindow();
                dialog.ShowDialog();

                viewModelCommunication.Send(new HideDisabledOverlay());
            }
                );

            ConfirmChanges = new Command(() => viewModelCommunication.Send(new ConfirmChanges()));
            RejectChanges  = new Command(() => viewModelCommunication.Send(new RejectChanges()));

            BeginTime   = appointment.StartTime;
            EndTime     = appointment.EndTime;
            Description = appointment.Description;
            LabelColor  = appointment.Label.Color;

            ShowDisabledOverlay = false;

            SetNewLocation(initialLocalisation, true);
        }