public QueryParamsVM New() { var queryParamsVM = new QueryParamsVM(); queryParamsVM.Years = Years; queryParamsVM.Months = Months; queryParamsVM.TimeOfDay = TimeOfDay; queryParamsVM.DayOfWeek = DayOfWeek; queryParamsVM.ApptSelected = ""; queryParamsVM.DaySelected = ""; queryParamsVM.MonthSelected = ""; queryParamsVM.TODSelected = ""; queryParamsVM.YearSelected = ""; queryParamsVM.DoctorName = ""; return(queryParamsVM); }
public async Task <List <Schedule> > ProcessQuery(QueryParamsVM queryParamsVM) { int Year; Int32.TryParse(queryParamsVM.YearSelected, out Year); int month = Months[queryParamsVM.MonthSelected]; System.DayOfWeek dow = DayOfWeek[queryParamsVM.DaySelected]; var Schedules = (await _scheduleDataService.GetSchedules()) .Where(s => s.Date.Year == Year && s.Date.Month == month && s.Date.DayOfWeek == dow && s.Date >= DateTime.Now && s.Open == true) .ToList(); int lowerHour = 8; int upperHour = 16; if (queryParamsVM.TODSelected == "Morning") { lowerHour = 8; upperHour = 11; } else if (queryParamsVM.TODSelected == "Noon") { lowerHour = 11; upperHour = 13; } else if (queryParamsVM.TODSelected == "Afternoon") { lowerHour = 13; upperHour = 16; } else { lowerHour = 8; upperHour = 16; } Schedules = Schedules.Where(s => s.Date.Hour >= lowerHour && s.Date.Hour <= upperHour).ToList(); return(Schedules); }
public async Task MakeAppointment(QueryParamsVM queryParamsVM, List <Schedule> schedules, string userName) { // get date selected int apptId = Int32.Parse(queryParamsVM.ApptSelected); Schedule schedule = schedules.Where(s => s.Id == apptId).FirstOrDefault(); DateTime date; if (schedule == null) { throw new System.InvalidOperationException("Cannot obtain a Schedule entry"); } date = schedule.Date; // add apointment to customers database Appointment appointment = new Appointment { UserName = userName, Date = date, Duration = 30, Cancelled = false, DoctorName = queryParamsVM.DoctorName }; await _appointmentDataService.AddAppointment(appointment); var appt = (await _appointmentDataService.GetAppointments()) .Where(a => a.UserName == userName && a.Date == date) .FirstOrDefault(); if (appt == null) { throw new System.InvalidOperationException("Cannot create an appointment record"); } apptId = appt.Id; schedule.Open = false; schedule.ApptId = apptId; await _scheduleDataService.UpdateSchedule(schedule); }