Example #1
0
        public IList<CategoryDataTableModel> GetDataTable(string term, int page, int count,
            Order order, CategoryOrderBy orderBy, CategorySearchBy searchBy)
        {
            IQueryable<Category> selectedCategories = _categories.AsQueryable();

            if (!string.IsNullOrEmpty(term))
            {
                switch (searchBy)
                {
                    case CategorySearchBy.Name:
                        selectedCategories =
                            selectedCategories.Where(category => category.Name.Contains(term)).AsQueryable();
                        break;
                    case CategorySearchBy.Description:
                        selectedCategories =
                            selectedCategories.Where(category => category.Description.Contains(term)).AsQueryable();
                        break;
                }
            }

            if (order == Order.Asscending)
            {
                switch (orderBy)
                {
                    case CategoryOrderBy.Id:
                        selectedCategories = selectedCategories.OrderBy(category => category.Id).AsQueryable();
                        break;
                    case CategoryOrderBy.Name:
                        selectedCategories = selectedCategories.OrderBy(category => category.Name).AsQueryable();
                        break;
                }
            }
            else
            {
                switch (orderBy)
                {
                    case CategoryOrderBy.Id:
                        selectedCategories = selectedCategories.OrderByDescending(category => category.Id).AsQueryable();
                        break;
                    case CategoryOrderBy.Name:
                        selectedCategories =
                            selectedCategories.OrderByDescending(category => category.Name).AsQueryable();
                        break;
                }
            }

            return selectedCategories.Select(category => new CategoryDataTableModel
            {
                Name = category.Name,
                Description = category.Description,
                Id = category.Id,
                ArticlesCount = category.Articles.Count,
                Order = category.Order,
            }).Skip(page * count).Take(count).ToList();
        }
Example #2
0
        public virtual ActionResult DataTable(string term = "", int page = 0, int count = 10,
                                              Order order = Order.Descending, CategoryOrderBy orderBy = CategoryOrderBy.Id,
                                              CategorySearchBy searchBy = CategorySearchBy.Name)
        {
            ViewBag.CurrentPage = page;
            ViewBag.Count       = count;

            ViewBag.TERM     = term;
            ViewBag.PAGE     = page;
            ViewBag.COUNT    = count;
            ViewBag.ORDER    = order;
            ViewBag.ORDERBY  = orderBy;
            ViewBag.SEARCHBY = searchBy;

            var selectListOrderBy = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "تاریخ", Value = "Id"
                },
                new SelectListItem {
                    Text = "نام", Value = "Name"
                },
            };

            ViewBag.OrderByItems = new SelectList(selectListOrderBy, "Value", "Text", orderBy);

            ViewBag.OrderByList = DropDownList.OrderList(order);

            ViewBag.CountList = DropDownList.CountList(count);

            IList <CategoryDataTableModel> model = _categoryService.GetDataTable(term, page, count, order, orderBy,
                                                                                 searchBy);

            ViewBag.TotalRecords = (string.IsNullOrEmpty(term)) ? _categoryService.Count : model.Count;

            return(PartialView(MVC.Admin.Category.Views._DataTable, model));
        }
Example #3
0
        public IList <CategoryDataTableModel> GetDataTable(string term, int page, int count,
                                                           Order order, CategoryOrderBy orderBy, CategorySearchBy searchBy)
        {
            IQueryable <Category> selectedCategories = _categories.AsQueryable();

            if (!string.IsNullOrEmpty(term))
            {
                switch (searchBy)
                {
                case CategorySearchBy.Name:
                    selectedCategories =
                        selectedCategories.Where(category => category.Name.Contains(term)).AsQueryable();
                    break;

                case CategorySearchBy.Description:
                    selectedCategories =
                        selectedCategories.Where(category => category.Description.Contains(term)).AsQueryable();
                    break;
                }
            }

            if (order == Order.Asscending)
            {
                switch (orderBy)
                {
                case CategoryOrderBy.Id:
                    selectedCategories = selectedCategories.OrderBy(category => category.Id).AsQueryable();
                    break;

                case CategoryOrderBy.Name:
                    selectedCategories = selectedCategories.OrderBy(category => category.Name).AsQueryable();
                    break;
                }
            }
            else
            {
                switch (orderBy)
                {
                case CategoryOrderBy.Id:
                    selectedCategories = selectedCategories.OrderByDescending(category => category.Id).AsQueryable();
                    break;

                case CategoryOrderBy.Name:
                    selectedCategories =
                        selectedCategories.OrderByDescending(category => category.Name).AsQueryable();
                    break;
                }
            }

            return(selectedCategories.Select(category => new CategoryDataTableModel
            {
                Name = category.Name,
                Description = category.Description,
                Id = category.Id,
                ArticlesCount = category.Articles.Count,
                Order = category.Order,
            }).Skip(page * count).Take(count).ToList());
        }