public ActionResult Index(CoursesReportViewModel model, int?page, string searchCheck)
        {
            List <Student_Course_Log> LogList = new List <Student_Course_Log>();
            string SearchString = model.Email;

            model.searchCheck = searchCheck;
            List <string> listSubjiect = unitOfWork.Subject.GetAll().Select(o => o.Subject_Name).ToList();

            model.listSubject = listSubjiect;
            if (searchCheck == null)
            {
                page = 1;
            }
            else
            {
                LogList = unitOfWork.CoursesLog.GetPageList();
            }
            if (!String.IsNullOrEmpty(searchCheck))
            {
                if (!String.IsNullOrEmpty(SearchString))
                {
                    LogList = LogList.Where(s => s.Email.ToUpper().Contains(SearchString.ToUpper())).ToList();
                }
                if (!String.IsNullOrEmpty(model.Date_Import.ToString()))
                {
                    LogList = LogList.Where(s => s.Date_Import == model.Date_Import).ToList();
                }
                if (model.completedCourse)
                {
                    LogList = LogList.Where(s => s.Completed == true).ToList();
                }
                if (model.compulsoryCourse)
                {
                    LogList = LogList.Where(s => s.Course_ID != null).ToList();
                }
                if (!String.IsNullOrEmpty(model.Subject_Name))
                {
                    var sub = unitOfWork.Subject.GetAll().Where(x => x.Subject_Name == model.Subject_Name).Select(y => y.Subject_ID).FirstOrDefault();
                    LogList = LogList.Where(s => s.Subject_ID == sub).ToList();
                }
            }
            ViewBag.Count = LogList.Count();
            int pageSize   = 30;
            int pageNumber = (page ?? 1);

            model.PageList = LogList.ToList().ToPagedList(pageNumber, pageSize);
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Index(CoursesReportViewModel model, int?page, string searchCheck)
        {
            List <Student_Course_Log> LogList = new List <Student_Course_Log>();
            string SearchString = model.Email;

            model.searchCheck = searchCheck;
            List <SelectListItem> listSubjiect = new List <SelectListItem>();
            var subject = unitOfWork.Subject.GetAll();

            foreach (var sub in subject)
            {
                if (sub.Subject_Active == true)
                {
                    listSubjiect.Add(new SelectListItem
                    {
                        Text  = sub.Subject_Name,
                        Value = sub.Subject_ID
                    });
                }
            }
            List <SelectListItem> campusList = new List <SelectListItem>();
            var campus = unitOfWork.Campus.GetAll();

            foreach (var cam in campus)
            {
                campusList.Add(new SelectListItem
                {
                    Text  = cam.Campus_Name,
                    Value = cam.Campus_ID
                });
            }
            List <SelectListItem> semesterList = new List <SelectListItem>();
            var semester = unitOfWork.Semesters.GetAll();

            semester = semester.OrderByDescending(m => m.Start_Date).ToList();
            if (semester.Count > 0)
            {
                var index = semester.FindIndex(m => m.Start_Date <DateTime.Now && m.End_Date> DateTime.Now);
                if (index != -1)
                {
                    var Item = semester[index];
                    semester[index] = semester[0];
                    semester[0]     = Item;
                }
            }
            foreach (var sem in semester)
            {
                semesterList.Add(new SelectListItem
                {
                    Text  = sem.Semester_Name,
                    Value = sem.Semester_ID
                });
            }
            List <string> date = new List <string>();

            try
            {
                List <DateTime?> listDate = new List <DateTime?>();
                if (string.IsNullOrEmpty(model.Semester_ID))
                {
                    listDate = unitOfWork.CoursesLog.GetAll().OrderByDescending(o => o.Date_Import).Where(o => o.Semester_ID == semester[0].Semester_ID).Select(o => o.Date_Import).Distinct().ToList();
                }
                else
                {
                    listDate = unitOfWork.CoursesLog.GetAll().OrderByDescending(o => o.Date_Import).Where(o => o.Semester_ID == model.Semester_ID).Select(o => o.Date_Import).Distinct().ToList();
                }
                foreach (var dates in listDate)
                {
                    date.Add(Convert.ToDateTime(dates).ToString("dd/MM/yyyy"));
                }
            }
            catch
            {
                date = new List <string>();
            }
            model.importedDate = date;
            model.lstSemester  = semesterList;
            model.lstCampus    = campusList;
            model.listSubject  = listSubjiect;
            if (searchCheck == null)
            {
                page = 1;
            }
            else
            {
                LogList = unitOfWork.CoursesLog.GetPageList();
            }
            if (!String.IsNullOrEmpty(searchCheck))
            {
                if (!String.IsNullOrWhiteSpace(SearchString))
                {
                    LogList = LogList.Where(s => s.Email.Trim().ToUpper().Contains(SearchString.Trim().ToUpper())).ToList();
                }
                if (!String.IsNullOrWhiteSpace(model.ImportedDate))
                {
                    DateTime dt = DateTime.ParseExact(model.ImportedDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    LogList = LogList.Where(s => s.Date_Import == dt).ToList();
                }
                if (model.completedCourse != null)
                {
                    LogList = model.completedCourse == "Yes" ? LogList.Where(s => s.Completed == true).ToList() : LogList.Where(s => s.Completed == false).ToList();
                }
                if (model.compulsoryCourse != null)
                {
                    LogList = model.compulsoryCourse == "Yes" ? LogList = LogList.Where(s => s.Subject_ID != "").ToList() : LogList = LogList.Where(s => s.Subject_ID == "").ToList();
                }
                if (!String.IsNullOrWhiteSpace(model.Subject_ID))
                {
                    LogList = LogList.Where(s => s.Subject_ID == model.Subject_ID).ToList();
                }
                if (!String.IsNullOrWhiteSpace(model.Campus))
                {
                    LogList = LogList.Where(s => s.Campus == model.Campus).ToList();
                }
                if (!String.IsNullOrWhiteSpace(model.Semester_ID))
                {
                    LogList = LogList.Where(s => s.Semester_ID == model.Semester_ID).ToList();
                }
                if (LogList.Count == 0)
                {
                    ViewBag.Nodata = "Showing 0 results";
                }
                else
                {
                    ViewBag.Nodata = "";
                }
            }
            List <string> completedCour = new List <string>()
            {
                "Yes", "No"
            };
            List <string> compulsoryCour = new List <string>()
            {
                "Yes", "No"
            };

            model.completedCour  = completedCour;
            model.compulsoryCour = compulsoryCour;
            ViewBag.CountRoll    = LogList.Select(o => o.Roll).Distinct().Count();
            ViewBag.CountLog     = LogList.Count();
            int pageSize   = 30;
            int pageNumber = (page ?? 1);

            model.PageList = LogList.ToList().ToPagedList(pageNumber, pageSize);
            return(View(model));
        }