Ejemplo n.º 1
0
        public virtual ActionResult List(string term = "", int page = 1, int count = 10,
                                         Order order = Order.Descending, ProfessorSearchBy objSearchBy = ProfessorSearchBy.FirstName)
        {
            //#region Retrive Data
            int total;
            var articles = _ProfessorService.GetDataTable(out total, term, page, order, objSearchBy, count);
            var model    = new ProfessorListVM
            {
                Order           = order,
                PageCount       = count,
                PageNumber      = page,
                ProfessorList   = articles,
                Term            = term,
                TotalProfessors = total
            };

            ViewBag.CountList = DropDown.GetCountList(count);
            ViewBag.OrderList = DropDown.GetOrderList(order);
            return(PartialView("_ListPartial", model));
        }
Ejemplo n.º 2
0
        public IEnumerable <ProfessorViewModel> GetDataTable(out int total, string term, int page,
                                                             Order order, ProfessorSearchBy slectionSearchBy, int count = 10)
        {
            var selectedobj = _Professor
                              .Include(x => x.Group)
                              .Include(x => x.User)
                              .AsNoTracking().AsQueryable();

            if (!string.IsNullOrEmpty(term))
            {
                switch (slectionSearchBy)
                {
                case ProfessorSearchBy.BirthDate:
                    selectedobj = selectedobj.Where(a => a.BirthDay.Value.ToShortDateString().Contains(term)).AsQueryable(); break;

                case ProfessorSearchBy.Education:
                    selectedobj = selectedobj.Where(a => a.Edution.Contains(term)).AsQueryable(); break;

                case ProfessorSearchBy.FirstName:
                    selectedobj = selectedobj.Where(a => a.FirstName.Contains(term)).AsQueryable(); break;

                case ProfessorSearchBy.LastName:
                    selectedobj = selectedobj.Where(a => a.LastName.Contains(term)).AsQueryable(); break;

                case ProfessorSearchBy.PNO:
                    selectedobj = selectedobj.Where(a => a.PNO.Contains(term)).AsQueryable(); break;

                case ProfessorSearchBy.Tendency:
                    selectedobj = selectedobj.Where(a => a.Tendency.Contains(term)).AsQueryable(); break;
                }
            }
            if (order == Order.Asscending)
            {
                selectedobj = selectedobj.OrderBy(x => x.Id).AsQueryable();
            }
            else
            {
                selectedobj = selectedobj.OrderByDescending(x => x.Id).AsQueryable();
            }

            var totalQuery = selectedobj.FutureCount();
            var query      = selectedobj.Skip((page - 1) * count).Take(count)
                             .Select(a => new ProfessorViewModel
            {
                Id                 = a.Id,
                AvatarPath         = a.AvatarPath,
                BirthDay           = a.BirthDay,
                Edution            = a.Edution,
                FirstName          = a.FirstName,
                Gender             = a.Gender,
                LastName           = a.LastName,
                PNO                = a.PNO,
                Tendency           = a.Tendency,
                PeresentedCourcess = a.PeresentedCourses,
                User               = a.User,
                Group              = a.Group,

                Group_Id = a.Group.Id
            }).Future();

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

            return(categories);
        }