//public NotiTimeFrameViewModel scheduleNotis(DateTime date, int doctorid, string TimeFrame) //{ // using(var ctx = new CaremeDBContext()) // { // var day = date.DayOfWeek.ToString(); // DateTime? combined = null; // List<tbSchedule> schedules = ctx.tbSchedules.Where(a => a.IsDeleted != true // && a.DoctorID == doctorid).Where(daysQuery(day)).ToList(); // List<NotiViewModel> NotiList = new List<NotiViewModel>(); // foreach (var item in schedules) // { // combined = HelperExtension.getCombinedDateTime(date, item.Fromtime); // var appointments = ctx.tbAppointments.Where(a => a.IsDeleted != true // && a.DoctorId == item.DoctorID // && a.HospitalId == item.HospitalID && a.Day == day // && a.AppointmentDateTime == combined); // NotiViewModel notiMD = new NotiViewModel(); // notiMD.scheduleID = item.ID; // notiMD.AppointmentDateTime = combined ?? date; // notiMD.hospitalID = item.HospitalID ?? 0; // notiMD.hospitalName = item.HospitalName; // notiMD.patientCount = appointments.Count(); // if (notiMD.patientCount > 0) // { // notiMD.LastActivtBookedTime = appointments.OrderByDescending(a => a.Accesstime) // .FirstOrDefault().Accesstime ?? date; // } // NotiList.Add(notiMD); // } // NotiTimeFrameViewModel NotiObj = new NotiTimeFrameViewModel(); // if(schedules.Count > 0) // { // NotiObj.NotiList = NotiList; // NotiObj.Timeframe = TimeFrame; // } // return NotiObj; // } //} public NotiTimeFrameViewModel scheduleNotis(DateTime date, int doctorid, string TimeFrame) { using (var ctx = new CaremeDBContext()) { date = date.Date; var day = date.DayOfWeek.ToString(); DateTime?combined = null; //List<tbSchedule> schedules = ctx.tbSchedules.Where(a => a.IsDeleted != true // && a.DoctorID == doctorid).Where(daysQuery(day)).ToList(); var dateto = date.AddDays(1).Date; List <tbScheduleData> schedules = ctx.tbScheduleDatas.Where(a => a.IsDeleted != true && a.DoctorID == doctorid && a.AppointmentDatetime >= date && a.AppointmentDatetime <= dateto).ToList(); List <NotiViewModel> NotiList = new List <NotiViewModel>(); foreach (var item in schedules) { //combined = HelperExtension.getCombinedDateTime(date, item.Fromtime); var appointments = ctx.tbAppointments.Where(a => a.IsDeleted != true && a.DoctorId == item.DoctorID && a.HospitalId == item.HospitalID && a.AppointmentDateTime == item.AppointmentDatetime); NotiViewModel notiMD = new NotiViewModel(); notiMD.scheduleID = item.ID; notiMD.AppointmentDateTime = item.AppointmentDatetime ?? date; notiMD.hospitalID = item.HospitalID ?? 0; notiMD.hospitalName = item.HospitalName; notiMD.patientCount = appointments.Count(); notiMD.MaxPatientCount = item.MaxPatientCount ?? 0; notiMD.IsLimited = item.IsLimited; notiMD.IsStopped = item.IsStopped; if (notiMD.patientCount > 0) { notiMD.LastActivtBookedTime = appointments.OrderByDescending(a => a.Accesstime) .FirstOrDefault().Accesstime ?? date; } NotiList.Add(notiMD); } NotiTimeFrameViewModel NotiObj = new NotiTimeFrameViewModel(); if (schedules.Count > 0) { NotiObj.NotiList = NotiList; NotiObj.Timeframe = TimeFrame; } return(NotiObj); } }
public HttpResponseMessage getNotiList(HttpRequestMessage request, int doctorid = 0) { List <NotiTimeFrameViewModel> NotiResultList = new List <NotiTimeFrameViewModel>(); DateTime TodayDate = MyExtension.getLocalTime(DateTime.UtcNow); NotiTimeFrameViewModel todayNotiObj = iScheduleService.scheduleNotis(TodayDate, doctorid, "Today"); DateTime yesterdayDate = TodayDate.AddDays(-1); NotiTimeFrameViewModel yesterdayNotiObj = iScheduleService.scheduleNotis(yesterdayDate, doctorid, "Yesterday"); if (todayNotiObj.Timeframe != null) { NotiResultList.Add(todayNotiObj); } if (yesterdayNotiObj.Timeframe != null) { NotiResultList.Add(yesterdayNotiObj); } return(request.CreateResponse <List <NotiTimeFrameViewModel> >(HttpStatusCode.OK, NotiResultList)); }