public List <AppointmentsDateAndTimeInformation> GetAppointmentsForCustomer(int userId) { var user = Context.Users.Where(c => c.Id == userId).First(); List <AppointmentsDateAndTimeInformation> appointmentsForCustomer = new List <AppointmentsDateAndTimeInformation>(); Customer customer = Context.Customers.Where(c => c.Id == user.IdCustomer).First(); List <Appointment> appointments = Context.Appointments.Where(c => c.IdCustomer == customer.Id && c.IsActive == true).ToList(); foreach (var appointment in appointments) { DateTime startTime = Context.TimeSlots.Where(c => c.Id == appointment.IdTimeSlot).First().StartDateTime; DateTime endTime = Context.TimeSlots.Where(c => c.Id == appointment.IdTimeSlot).First().EndDateTime; if (startTime.Date >= DateConverter.CurrentEasternDateTime().Date) { AppointmentsDateAndTimeInformation oneAppointment = new AppointmentsDateAndTimeInformation { Appointment = appointment, Date = startTime.Date.ToString(), StartTime = startTime.TimeOfDay.ToString(), EndTime = endTime.TimeOfDay.ToString() }; appointmentsForCustomer.Add(oneAppointment); } } appointmentsForCustomer = appointmentsForCustomer.OrderBy(c => c.Date).OrderBy(c => c.StartTime).ToList(); return(appointmentsForCustomer); }
public List <AppointmentsDateAndTimeInformation> GetOldAppointmentsForACustomer(int userId) { var user = Context.Users.First(c => c.Id == userId); var appointmentsForCustomers = new List <AppointmentsDateAndTimeInformation>(); Customer customer = Context.Customers.First(c => c.Id == user.IdCustomer); List <Appointment> appointments = Context.Appointments.Where(c => c.IdCustomer == customer.Id).ToList(); foreach (var appointment in appointments) { var timeSlot = Context.TimeSlots.First(c => c.Id == appointment.IdTimeSlot); if (timeSlot.StartDateTime.Date <= DateConverter.CurrentEasternDateTime().Date) { AppointmentsDateAndTimeInformation newAppointment = new AppointmentsDateAndTimeInformation { Appointment = appointment, Date = timeSlot.StartDateTime.Date.ToString(), StartTime = timeSlot.StartDateTime.TimeOfDay.ToString(), EndTime = timeSlot.EndDateTime.TimeOfDay.ToString() }; appointmentsForCustomers.Add(newAppointment); } } appointmentsForCustomers = appointmentsForCustomers.OrderBy(c => c.Date).OrderBy(c => c.StartTime).ToList(); return(appointmentsForCustomers); }