public HttpResponseMessage FetchDoctorTimeWeb(FetchTimingsModel searchModel) { try { //var dateTime = DateTime.Parse(searchModel.appDate); string[] formats = { "dd/MM/yyyy" }; var dateTime = DateTime.ParseExact(searchModel.appDate.Trim(), formats, new CultureInfo("en-US"), DateTimeStyles.None); string appday = dateTime.ToString("dddd"); //var result = db.SP_FetchDoctorTimings(searchModel.doctorID, dateTime).ToList(); var timings = (from t in db.DoctorTimings where t.doctorID == searchModel.doctorID && t.utcDay == appday && t.active == true select new TimingsVM { doctorID = t.doctorID, fromtime = t.@from, totime = t.to }).ToList(); var appointments = (from app in db.Appointments where app.doctorID == searchModel.doctorID && app.appDate == dateTime select new AppointmentsVM { appTime = app.appTime }).ToList(); DocTimingsAndAppointment result = new DocTimingsAndAppointment(); result.timingsVM = timings; result.appointmentVM = appointments; response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); } catch (Exception ex) { return(ThrowError(ex, "FetchDoctorTimeWeb in SearchDoctorController")); } }
public HttpResponseMessage FetchDoctorTimeNew(FetchTimingsModel searchModel) { try { //var dateTime = DateTime.Parse(searchModel.appDate); string[] formats = { "dd/MM/yyyy" }; var dateTime = DateTime.ParseExact(searchModel.appDate.Trim(), formats, new CultureInfo("en-US"), DateTimeStyles.None); string appday = dateTime.ToString("dddd"); //List<SP_FetchDoctorTimings_Result> appList = new List<SP_FetchDoctorTimings_Result>(); //appList = db.SP_FetchDoctorTimings(searchModel.doctorID, dateTime).ToList(); var doctimings = (from t in db.DoctorTimings where t.doctorID == searchModel.doctorID && t.utcDay == appday && t.active == true select new TimingsVM { doctorID = t.doctorID, fromtime = t.@from, totime = t.to }).ToList(); var appointments = (from app in db.Appointments where app.doctorID == searchModel.doctorID && app.appDate == dateTime select new AppointmentsVM { appTime = app.appTime }).ToList(); DocTimingsAndAppointment appList = new DocTimingsAndAppointment(); appList.timingsVM = doctimings; appList.appointmentVM = appointments; List <string> timings = new List <string>(); if (appList != null) { //calculate time slots timings = createTimeSlots(appList);//displayTimeSlots(appList); timings = timings.OrderBy(x => DateTime.ParseExact(x, "hh:mm tt", CultureInfo.InvariantCulture)).ToList(); //timings = displayTimeSlots(appList);//displayTimeSlots(appList); } response = Request.CreateResponse(HttpStatusCode.OK, timings); return(response); } catch (Exception ex) { return(ThrowError(ex, "FetchDoctorTimeNew in SearchDoctorController")); } }
public JsonResult FetchDoctorTimingsNew(FetchTimingsModel model) { try { SeeDoctorRepository objSeeDoctorRepo = new SeeDoctorRepository(); DocTimingsAndAppointment appList = new DocTimingsAndAppointment(); appList = objSeeDoctorRepo.FetchDoctorTimesNew(model); List <string> timings = new List <string>(); if (appList != null) { //calculate time slots timings = createTimeSlots(appList); } return(Json(new { Success = true, Object = timings })); } catch (System.Web.Http.HttpResponseException ex) { return(Json(new { Message = ex.Response })); } }
private List <string> createTimeSlots(DocTimingsAndAppointment appList) { List <string> timeSlots = new List <string> { }; foreach (var item in appList.timingsVM) { TimeSpan startTime = (TimeSpan)item.fromtime; TimeSpan endTime = (TimeSpan)item.totime; if (startTime.Minutes % 15 != 0) { TimeSpan tempp = TimeSpan.FromMinutes(15 - (startTime.Minutes % 15)); startTime = startTime.Add(tempp); if (!(timeSlots.Contains(startTime.ToString(@"hh\:mm")))) { timeSlots.Add(startTime.ToString(@"hh\:mm")); TimeSpan temppp = TimeSpan.FromMinutes(15); startTime = startTime.Add(temppp); } } if (endTime.Minutes % 15 != 0) { TimeSpan tempp = TimeSpan.FromMinutes(15 - (endTime.Minutes % 15)); endTime = endTime.Add(tempp); } TimeSpan itemstartTime = startTime;//(TimeSpan)item.from; if (!(timeSlots.Contains(startTime.ToString(@"hh\:mm")))) { timeSlots.Add(startTime.ToString(@"hh\:mm")); TimeSpan tempp = TimeSpan.FromMinutes(15); startTime = startTime.Add(tempp); } bool flag = true; while (flag) { if (!(timeSlots.Contains(startTime.ToString(@"hh\:mm")))) { //if (!(TimeSpan.Equals(slot, item.appTime))) //{ timeSlots.Add(startTime.ToString(@"hh\:mm")); TimeSpan tempp = TimeSpan.FromMinutes(15); startTime = startTime.Add(tempp); //} } else { TimeSpan tempp = TimeSpan.FromMinutes(15); startTime = startTime.Add(tempp); } if (TimeSpan.Equals(startTime, endTime)) { if (!(timeSlots.Contains(startTime.ToString(@"hh\:mm")))) { timeSlots.Add(startTime.ToString(@"hh\:mm")); TimeSpan tempp = TimeSpan.FromMinutes(15); startTime = startTime.Add(tempp); } flag = false; } if (startTime.Hours == endTime.Hours) { if (startTime.Minutes > endTime.Minutes) { flag = false; } } } //while end } //for loop for database records. foreach (var app in appList.appointmentVM) { if (app.appTime.HasValue) { TimeSpan apptime = TimeSpan.Parse(app.appTime.Value.ToString()); if (timeSlots.Contains(apptime.ToString(@"hh\:mm"))) { timeSlots.Remove(apptime.ToString(@"hh\:mm")); } } } for (var i = 0; i < timeSlots.Count; i++) { TimeSpan doctimings = TimeSpan.Parse(timeSlots[i]); var dateTime = new DateTime(doctimings.Ticks); // Date part is 01-01-0001 var formattedTime = dateTime.ToString("hh:mm tt", CultureInfo.InvariantCulture); timeSlots.RemoveAt(i); timeSlots.Insert(i, formattedTime); } if (timeSlots.Count > 0) { timeSlots.RemoveAt(timeSlots.Count - 1); } return(timeSlots); }