Exemple #1
0
 private DetailAppointment MapDetailAppointment(AppointmentRM appointment, Appointment newAppointment)
 {
     return(new DetailAppointment()
     {
         idAppointment = newAppointment.idAppointment,
         idClinic = appointment.ClinicId,
         idVet = appointment.VetId
     });
 }
Exemple #2
0
 private Appointment MapAppointmentFromRM(AppointmentRM appointment)
 {
     return(new Appointment()
     {
         idPet = appointment.PetId,
         appointmentDate = appointment.Date,
         title = appointment.Title,
         confirmed = false
     });
 }
Exemple #3
0
        public IHttpActionResult PostAppointment([FromBody] AppointmentRM appointment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                //  Search for pet
                var pet = context.Pets.FirstOrDefault(p => p.idPet == appointment.PetId);
                if (pet == null)
                {
                    return(NotFound());
                }

                //  Search for clinic
                var clinic = context.Clinics.FirstOrDefault(c => c.idClinic == appointment.ClinicId);
                if (clinic == null)
                {
                    //  If clinic is not found, search for vet
                    appointment.ClinicId = null;
                    var vet = context.Vets.FirstOrDefault(v => v.idVet == appointment.VetId);
                    if (vet == null)
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    appointment.VetId = null;
                }

                context.Connection.Open();
                using (context.Transaction = context.Connection.BeginTransaction())
                {
                    Appointment newAppointment = MapAppointmentFromRM(appointment);
                    newAppointment.attended = false;
                    context.Appointments.InsertOnSubmit(newAppointment);
                    context.SubmitChanges(ConflictMode.FailOnFirstConflict);

                    DetailAppointment newDetail = MapDetailAppointment(appointment, newAppointment);
                    context.DetailAppointments.InsertOnSubmit(newDetail);
                    context.SubmitChanges(ConflictMode.FailOnFirstConflict);

                    context.Transaction.Commit();
                    return(Ok(newAppointment));
                }
            }
            catch (Exception e)
            {
                context.Transaction?.Rollback();
                return(InternalServerError(e));
            }
        }
        public AppointmentViewModel(IAppointmentsService appointmentService, IVetsService vetsService)
        {
            _appointmentsService = appointmentService;
            _vetsService         = vetsService;

            Vets        = new ObservableRangeCollection <Vet>();
            Pet         = new Pet();
            Appointment = new AppointmentRM {
                Date = DateTime.Now
            };

            GoToVetSelectionCommand = new Command(async() => await GoToVetSelection(),
                                                  () => !IsBusy);
        }
Exemple #5
0
        public async Task <IActionResult> Checkout([FromBody] AppointmentRM appointment, [FromHeader(Name = "x-requestid")] string requestId)
        {
            Guid commandId = Guid.NewGuid();

            appointment.Id = Guid.NewGuid();

            var makeAnAppointmentCommand = new MakeAnAppointmentCommand(
                commandId,
                appointment.Id,
                appointment.SiteId,
                appointment.LocationId,
                appointment.StaffId,
                appointment.StartDateTime, appointment.EndDateTime,
                appointment.ClientId,
                appointment.GenderPreference,
                appointment.Duration,
                appointment.StaffRequested,
                appointment.Notes,
                appointment.AppointmentServiceItems,
                appointment.AppointmentResources
                );
            var result = false;

            Guid requestGuidId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
                                 guid : appointment.ClientId;

            var requestMakeAnAppointment = new IdentifiedCommand <MakeAnAppointmentCommand, bool>(makeAnAppointmentCommand, requestGuidId);

            result = await _mediator.Send(requestMakeAnAppointment);

            _logger.CreateLogger(nameof(AppointmentsController))
            .LogTrace(result ? $"MakeAnAppointmentCommand has been received and a create new appointment process is started with requestId: {makeAnAppointmentCommand.ClientId}" :
                      $"MakeAnAppointmentCommand has been received but a new appointment process has failed with requestId: {makeAnAppointmentCommand.ClientId}");

            return(Accepted());
        }
Exemple #6
0
        public async Task <Appointment> PostAppointment(AppointmentRM appointment)
        {
            var relativeUri = Uris.UriAppointments;

            return(await PostApiAsync <Appointment>(relativeUri, appointment.ToJson()));
        }