public GetAppointmentsResult Get(DateTime start, DateTime end) { Guid technicianId = GetTechnicianId(); GetAppointmentsResult result = _appointmentService.GetAppointments(start, end, technicianId); return(result); }
public GetAppointmentsResult GetAppointments(DateTime start, DateTime end, Guid technicianId) { start = ToUtcKind(start); end = ToUtcKind(end); var data = (from a in _context.ServiceAppointmentSet join incident in _context.IncidentSet on a.Incident_ServiceAppointments.Id equals incident.IncidentId join account in _context.AccountSet on incident.ars_Location.Id equals account.AccountId where (a.ScheduledStart >= start && a.ScheduledStart <= end) || (a.ScheduledEnd >= start && a.ScheduledEnd <= end) where a.ars_Technician.Id == technicianId select new { Customer = account, Appointment = a, Incident = incident }).ToArray(); var models = new List <AppointmentModel>(); var result = new GetAppointmentsResult { HaveWorkForTomorrow = data.Any(d => d.Appointment.ScheduledEnd > end) }; foreach (var d in data) { models.Add(new AppointmentModel { Start = _timeService.ConvertUtcTimeToUserTime(d.Appointment.ScheduledStart.Value), End = _timeService.ConvertUtcTimeToUserTime(d.Appointment.ScheduledEnd.Value), Id = d.Appointment.Id, TicketNumber = d.Incident.TicketNumber, Address = d.Customer.Address1_Composite, Phone = d.Customer.Telephone1 ?? d.Customer.Telephone2 ?? d.Customer.Telephone3, Subject = d.Appointment.Subject, WorkOrderId = d.Incident.IncidentId.Value }); } result.Appointments = models.ToArray(); return(result); }