Beispiel #1
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            errors.Clear();

            if (ExecuteValidations())
            {
                //Although we work binding an object to the XAML, we did not want to give
                //to the view for edit the actual object being changed, so when we set
                //the Entity, the datacontext is loaded with a copy of the object
                //and when the user finally saves it, we set the properties
                //of our entity (that is the one shown in the grid) with the values from the
                //view (DataContext).
                Appointment changedAppointment = (Appointment)fieldsGrid.DataContext;

                appointment.Address               = changedAppointment.Address;
                appointment.AppointmentType       = changedAppointment.AppointmentType;
                appointment.DateTimeOfAppointment = changedAppointment.DateTimeOfAppointment;
                appointment.Id                = changedAppointment.Id;
                appointment.IdAddress         = changedAppointment.IdAddress;
                appointment.IdAppointmentType = changedAppointment.IdAppointmentType;
                appointment.Client            = changedAppointment.Client;
                appointment.Doctor            = changedAppointment.Doctor;
                appointment.Pet               = changedAppointment.Pet;

                //It could be bound through the interface, but what I want to do is to allow that the errors are shown here
                ResultOperation result = appointmentModel.Save(changedAppointment);

                if (result.Success)
                {
                    OnSave?.Invoke();
                }
                else
                {
                    errors.AddRange(result.Errors);
                }
            }

            if (errors.Any())
            {
                lblErrors.Content = UIHelper.GetStringFromList(errors);
            }
        }