public async Task <HttpResponseMessage> GetLectureDashboard(int accessorID, string role, int courseID = 0) { try { MIUEntities db = new MIUEntities(); LectureDashboardInfo data = new LectureDashboardInfo(); StudentDashboardDAL dal = new StudentDashboardDAL(); NewsDAL newsDAL = new NewsDAL(); ResultDAL resultDAL = new ResultDAL(); AnnouncementDAL announcementDAL = new AnnouncementDAL(); EventCalendarDAL eventDAL = new EventCalendarDAL(); //data.AttRateAndPercent = await reportAttendanceDAL.GetAttRateAndPercent(batchID, userID); data = await dal.GetLectureDashboard(accessorID, courseID); data.Announcement = await announcementDAL.GetLatestAnnouncement(); data.News = newsDAL.GetNews(accessorID, 1, 5).Result; data.EventCalendar = eventDAL.GetAllEventCalendar(accessorID, role).Result; //data.EventCalendar = eventDAL.GetEventCalendar(accessorID, 1, 5).Result; if (data != null) { return(Request.CreateResponse <LectureDashboardInfo>(HttpStatusCode.OK, data)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, Constants.ErrorNotFound)); } } catch (DbEntityValidationException ex) { var controllerName = ControllerContext.RouteData.Values["controller"].ToString(); var actionName = ControllerContext.RouteData.Values["action"].ToString(); Logger log = new Logger(); log.ErrorLog(ex, controllerName, actionName); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Constants.ErrorSysError)); } }
public Task <LectureDashboardInfo> GetLectureDashboard(int accessorID, int courseID) // accessorID = 545, courseID = 9 { return(Task.Run(() => { using (MIUEntities db = new MIUEntities()) { LectureDashboardInfo infoList = new LectureDashboardInfo(); List <LectureResultInfo> LectureResultInfo = new List <LectureResultInfo>(); //List<User> stdList = new List<User>(); //try //{ var currentTime = DateTime.Now.ToString("h:mm tt", CultureInfo.InvariantCulture); var time = DateTime.ParseExact(currentTime, "h:mm tt", CultureInfo.InvariantCulture); if (courseID == 0) { var module = (from td in db.TermDetails join ttd in db.TimeTableDetails on td.ID equals ttd.TermDetailID join t in db.Terms on td.TermID equals t.ID join b in db.Batches on t.BatchID equals b.ID join c in db.Courses on b.CourseID equals c.ID join m in db.Modules on td.ModuleID equals m.ID where td.LectureID == accessorID && ttd.Date == DbFunctions.TruncateTime(DateTime.Now) select new LectureNextClass { CourseID = c.ID, CourseName = c.CourseName, ModuleID = td.ModuleID, ModuleName = m.ModuleName, Date = ttd.Date, StartTime = ttd.StartTime, EndTime = ttd.EndTime }).ToList(); foreach (var data in module) { if (DateTime.Now <= Convert.ToDateTime(data.StartTime)) { courseID = data.CourseID; infoList.Course = data.CourseName; infoList.Module = data.ModuleName; infoList.StartTime = data.StartTime; infoList.EndTime = data.EndTime; break; } } LectureResultInfo = GetLectureResult(accessorID, courseID); } else { var module = (from td in db.TermDetails join ttd in db.TimeTableDetails on td.ID equals ttd.TermDetailID join t in db.Terms on td.TermID equals t.ID join b in db.Batches on t.BatchID equals b.ID join c in db.Courses on b.CourseID equals courseID //With CourseID join m in db.Modules on td.ModuleID equals m.ID where td.LectureID == accessorID && ttd.Date == DbFunctions.TruncateTime(DateTime.Now) select new LectureNextClass { CourseID = c.ID, CourseName = c.CourseName, ModuleID = td.ModuleID, ModuleName = m.ModuleName, Date = ttd.Date, StartTime = ttd.StartTime, EndTime = ttd.EndTime }).ToList(); foreach (var data in module) { if (DateTime.Now <= Convert.ToDateTime(data.StartTime)) { infoList.Course = data.CourseName; infoList.Module = data.ModuleName; infoList.StartTime = data.StartTime; infoList.EndTime = data.EndTime; break; } } LectureResultInfo = GetLectureResult(accessorID, courseID); } infoList.LectureResultInfos = LectureResultInfo; return infoList; //} //catch (Exception ex) //{ // return infoList; //} } })); }