public virtual ActionResult List(string term = "", int page = 1, int count = 10,
                                         Order order = Order.Descending, PeresentedCoursesSearchBy objSearchBy = PeresentedCoursesSearchBy.Cource_Name,
                                         PeresentedCoursesOrderBy objOrderBy = PeresentedCoursesOrderBy.Id)
        {
            //#region Retrive Data
            int total;
            var articles = _PeresentedCoursesService.GetDataTable(out total, term, page, order, objSearchBy, objOrderBy, count);
            var model    = new PeresentedCoursesListVM
            {
                Order                 = order,
                PageCount             = count,
                PageNumber            = page,
                PeresentedCoursesList = articles,
                Term = term,
                TotalPeresentedCourses = total
            };

            ViewBag.CountList = DropDown.GetCountList(count);
            ViewBag.OrderList = DropDown.GetOrderList(order);
            return(PartialView("_ListPartial", model));
        }
        public IEnumerable <PeresentedCoursesViewModel> GetDataTable(out int total, string term, int page,
                                                                     Order order, PeresentedCoursesSearchBy slectionSearchBy, PeresentedCoursesOrderBy slectionOrderBy, int count = 10)
        {
            var selectedobj = _PeresentedCources
                              .Include(x => x.Course)
                              .Include(x => x.Professor)
                              .Include(x => x.Term)
                              .AsNoTracking().AsQueryable();

            if (!string.IsNullOrEmpty(term))
            {
                switch (slectionSearchBy)
                {
                case PeresentedCoursesSearchBy.Cource_Name:
                    selectedobj = selectedobj.Where(a => a.Course.Name.Contains(term)).AsQueryable(); break;

                case PeresentedCoursesSearchBy.Term:
                    selectedobj = selectedobj.Where(a => a.Term.Name.Contains(term)).AsQueryable(); break;

                case PeresentedCoursesSearchBy.Professor_Name:
                    selectedobj = selectedobj.Where(a => a.Professor.FirstName.Contains(term) ||
                                                    a.Professor.LastName.Contains(term)).AsQueryable(); break;
                }
            }
            if (order == Order.Asscending)
            {
                switch (slectionOrderBy)
                {
                case PeresentedCoursesOrderBy.Id:
                    selectedobj = selectedobj.OrderBy(x => x.Id).AsQueryable(); break;

                case PeresentedCoursesOrderBy.Cource:
                    selectedobj = selectedobj.OrderBy(x => x.Course.Id).AsQueryable(); break;

                case PeresentedCoursesOrderBy.Term:
                    selectedobj = selectedobj.OrderBy(x => x.Term.Id).AsQueryable(); break;
                }
            }
            else
            {
                switch (slectionOrderBy)
                {
                case PeresentedCoursesOrderBy.Id:
                    selectedobj = selectedobj.OrderByDescending(x => x.Id).AsQueryable(); break;

                case PeresentedCoursesOrderBy.Cource:
                    selectedobj = selectedobj.OrderByDescending(x => x.Course.Id).AsQueryable(); break;

                case PeresentedCoursesOrderBy.Term:
                    selectedobj = selectedobj.OrderByDescending(x => x.Term.Id).AsQueryable(); break;
                }
            }

            var totalQuery = selectedobj.FutureCount();
            var query      = selectedobj.Skip((page - 1) * count).Take(count)
                             .Select(a => new PeresentedCoursesViewModel
            {
                Id              = a.Id,
                Course          = a.Course,
                Elections       = a.Elections,
                Professor       = a.Professor,
                Term            = a.Term,
                Capacity        = a.Capacity,
                Remain_Capacity = a.Remain_Capacity,

                Course_Id    = a.Course.Id,
                Professor_Id = a.Professor.Id,
                Term_Id      = a.Term.Id
            }).Future();

            total = totalQuery.Value;
            var categories = query.ToList();

            return(categories);
        }