public ActionResult ReserveAnAppointment([FromBody] AppointmentUserInformation appointmentService)
 {
     if (appointmentService.IdUser != null ^ appointmentService.IdCustomer != null)
     {
         if (Service.ReserveAnAppointment(appointmentService, configuration))
         {
             return(Ok());
         }
         return(Conflict());
     }
     return(BadRequest());
 }
        public bool ReserveAnAppointment(AppointmentUserInformation appointmentService, IConfiguration configuration)
        {
            Appointment appointment = new Appointment();

            if (appointmentService != null)
            {
                appointment.CreatedOn = DateConverter.CurrentEasternDateTime();
                if (appointmentService.IdCustomer != null)
                {
                    appointment.IdCustomer = appointmentService.IdCustomer.Value;
                }
                else
                {
                    var customer = Context.Users.FirstOrDefault(c => c.Id == appointmentService.IdUser);
                    if (customer != null)
                    {
                        appointment.IdCustomer = customer.Id;
                    }
                    else
                    {
                        return(false);
                    }
                }
                appointment.IdTimeSlot         = appointmentService.IdTimeSlot;
                appointment.ConsultationReason = appointmentService.ConsultationReason;
                appointment.Therapist          = appointmentService.Therapist;
                appointment.HasSeenDoctor      = appointmentService.HasSeenDoctor;
                appointment.DoctorDiagnostic   = appointmentService.DoctorDiagnostic;
                appointment.IsNew    = true;
                appointment.IsActive = true;
                Context.Add(appointment);
                Context.SaveChanges();
                var user            = GetUser(appointment.IdCustomer);
                var appointmentDate = GetAppointmentTimeSlot(appointment).StartDateTime;
                if (user != null)
                {
                    EmailSender.SendConfirmationEmail(user.Email, appointmentDate, configuration);
                }
                return(true);
            }
            return(false);
        }