Exemplo n.º 1
0
 public void WhenTravelTimeQueryIsProcessedByTravelTimeService()
 {
     travelTimeJson = travelTimeService.GetTravelTime(travelTimeQuery);
 }
Exemplo n.º 2
0
        private bool CheckAllAppointments(Appointment appointmentToConfirm)
        {
            bool appointmentAvailable = false;

            appointmentToConfirm.Client = _context.Clients.Where(c => c.ClientId == appointmentToConfirm.ClientId).Include(c => c.Address).SingleOrDefault();
            List <Appointment> listOfAppointments = _context.Appointments.Where(a => a.DateTime.Date == appointmentToConfirm.DateTime.Date && a.Status == Constants.Appointment_Variables.Approved)
                                                    .Include(a => a.Client)
                                                    .Include(a => a.Client.Address)
                                                    .Include(a => a.Contractor)
                                                    .Include(a => a.Contractor.Address)
                                                    .ToList();

            if (listOfAppointments.Count == 0)
            {
                return(true);
            }
            foreach (Appointment appointment in listOfAppointments)
            {
                appointment.EndTime = appointment.DateTime.AddHours(1);
                appointment.DriveTimeToNewAppointment = _travelTimeService.GetTravelTime(appointment.Client.Address, appointmentToConfirm.Client.Address).Result;
            }
            for (int i = 0; i < listOfAppointments.Count; i++)
            {
                if ((i == 0) &&
                    (appointmentToConfirm.DateTime < listOfAppointments[i].DateTime)
                    )
                {
                    Console.WriteLine("appointmentToConfirm.DateTime" + appointmentToConfirm.DateTime);
                    Console.WriteLine("appointmentToConfirm.EndTime: " + appointmentToConfirm.EndTime);
                    Console.WriteLine("Drive time to appointment after appointmentToConfirm: " + listOfAppointments[i].DriveTimeToNewAppointment);
                    DateTime endOfAppointmentToConfirmPlusDriveTimetoAppoitnmentAfter = (appointmentToConfirm.EndTime.AddSeconds(listOfAppointments[i].DriveTimeToNewAppointment));
                    Console.WriteLine("End of appointmentToConfirmToConfirm Plus DriveTime: " + endOfAppointmentToConfirmPlusDriveTimetoAppoitnmentAfter);
                    Console.WriteLine();

                    bool CanIGetToAppointmentAfterAppointmentToConfirm = endOfAppointmentToConfirmPlusDriveTimetoAppoitnmentAfter < listOfAppointments[i].DateTime;
                    Console.WriteLine("Do I have time to get to the Appointment after appointmentToCofirm? " + CanIGetToAppointmentAfterAppointmentToConfirm);
                    Console.WriteLine();

                    Console.WriteLine("listOfAppointments[i].DateTime: " + listOfAppointments[i].DateTime);
                    Console.WriteLine("listOfAppointments[i].EndTime: " + listOfAppointments[i].EndTime);
                    Console.WriteLine("listOfAppointments[i].DriveTimeToNewAppointment: " + listOfAppointments[i].DriveTimeToNewAppointment);
                    Console.WriteLine();
                    if (
                        CanIGetToAppointmentAfterAppointmentToConfirm
                        )
                    {
                        appointmentAvailable = true;
                        break;
                    }
                }
                else if (
                    ((i == 0) && (appointmentToConfirm.DateTime > listOfAppointments[i].DateTime) && listOfAppointments.Count > 1) ||
                    ((i > 0) && (i < (listOfAppointments.Count - 1))
                    )
                    )
                {
                    Console.WriteLine("listOfAppointments[i].DateTime: " + listOfAppointments[i].DateTime);
                    Console.WriteLine("listOfAppointments[i].EndTime: " + listOfAppointments[i].EndTime);
                    Console.WriteLine("listOfAppointments[i].DriveTimeToNewAppointment: " + listOfAppointments[i].DriveTimeToNewAppointment);
                    DateTime endOfPriorAppointmentPlusDriveTime = (listOfAppointments[i].EndTime.AddSeconds(listOfAppointments[i].DriveTimeToNewAppointment));
                    Console.WriteLine("End of Previous Appointment Plus DriveTime: " + endOfPriorAppointmentPlusDriveTime);
                    Console.WriteLine();

                    bool CanIGetToAppointmentToConfirm = endOfPriorAppointmentPlusDriveTime < appointmentToConfirm.DateTime;
                    Console.WriteLine("Do I have time to get to the Appointment after first appointment? " + CanIGetToAppointmentToConfirm);
                    Console.WriteLine();

                    Console.WriteLine("appointmentToConfirm.DateTime" + appointmentToConfirm.DateTime);
                    Console.WriteLine("appointmentToConfirm.EndTime: " + appointmentToConfirm.EndTime);
                    Console.WriteLine("Drive time to appointment after appointmentToConfirm: " + listOfAppointments[i + 1].DriveTimeToNewAppointment);
                    DateTime endOfAppointmentToConfirmPlusDriveTimetoAppoitnmentAfter = (appointmentToConfirm.EndTime.AddSeconds(listOfAppointments[i + 1].DriveTimeToNewAppointment));
                    Console.WriteLine("End of appointmentToConfirmToConfirm Plus DriveTime: " + endOfAppointmentToConfirmPlusDriveTimetoAppoitnmentAfter);
                    Console.WriteLine();

                    bool CanIGetToAppointmentAfterAppointmentToConfirm = endOfAppointmentToConfirmPlusDriveTimetoAppoitnmentAfter < listOfAppointments[i + 1].DateTime;
                    Console.WriteLine("Do I have time to get to the Appointment after appointmentToCofirm? " + CanIGetToAppointmentAfterAppointmentToConfirm);
                    Console.WriteLine();

                    Console.WriteLine("listOfAppointments[i+1].DateTime: " + listOfAppointments[i + 1].DateTime);
                    Console.WriteLine("listOfAppointments[i+1].EndTime: " + listOfAppointments[i + 1].EndTime);
                    Console.WriteLine("listOfAppointments[i+1].DriveTimeToNewAppointment: " + listOfAppointments[i + 1].DriveTimeToNewAppointment);
                    Console.WriteLine();

                    if (
                        CanIGetToAppointmentToConfirm &&
                        CanIGetToAppointmentAfterAppointmentToConfirm
                        )
                    {
                        appointmentAvailable = true;
                        break;
                    }
                }
                else if (i == listOfAppointments.Count - 1)
                {
                    Console.WriteLine("listOfAppointments[i].DateTime: " + listOfAppointments[i].DateTime);
                    Console.WriteLine("listOfAppointments[i].EndTime: " + listOfAppointments[i].EndTime);
                    Console.WriteLine("listOfAppointments[i].DriveTimeToNewAppointment: " + listOfAppointments[i].DriveTimeToNewAppointment);
                    DateTime endOfPriorAppointmentPlusDriveTime = (listOfAppointments[i].EndTime.AddSeconds(listOfAppointments[i].DriveTimeToNewAppointment));
                    Console.WriteLine("End of Previous Appointment Plus DriveTime: " + endOfPriorAppointmentPlusDriveTime);
                    Console.WriteLine();

                    bool CanIGetToAppointmentToConfirm = endOfPriorAppointmentPlusDriveTime < appointmentToConfirm.DateTime;
                    Console.WriteLine("Do I have time to get to the Appointment after first appointment? " + CanIGetToAppointmentToConfirm);
                    Console.WriteLine();
                    if (
                        CanIGetToAppointmentToConfirm
                        )
                    {
                        appointmentAvailable = true;
                        break;
                    }
                }
            }

            return(appointmentAvailable);
        }