public virtual ActionResult DataTable(string term = "", int page = 0, int count = 10, Order order = Order.Asscending, LabelOrderBy orderBy = LabelOrderBy.Id, LabelSearchBy searchBy = LabelSearchBy.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"}, new SelectListItem {Text = "توضیحات", Value = "Description"}, new SelectListItem {Text = "تعداد پست ها", Value = "PostCount"} }; ViewBag.OrderByItems = new SelectList(selectListOrderBy, "Value", "Text", orderBy); ViewBag.OrderByList = DropDownList.OrderList(order); ViewBag.CountList = DropDownList.CountList(count); IList<LabelDataTableModel> model = _labelService.GetAll(term, page, count, order, orderBy, searchBy); ViewBag.TotalRecords = (string.IsNullOrEmpty(term)) ? _labelService.Count : model.Count; return PartialView(MVC.Admin.Label.Views._DataTable, model); }
public virtual ActionResult DataTable(string term = "", int page = 0, int count = 10, Order order = Order.Asscending, LabelOrderBy orderBy = LabelOrderBy.Id, LabelSearchBy searchBy = LabelSearchBy.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" }, new SelectListItem { Text = "توضیحات", Value = "Description" }, new SelectListItem { Text = "تعداد دانشنامه ها", Value = "PostCount" } }; ViewBag.OrderByItems = new SelectList(selectListOrderBy, "Value", "Text", orderBy); ViewBag.OrderByList = DropDownList.OrderList(order); ViewBag.CountList = DropDownList.CountList(count); IList <LabelDataTableModel> model = _labelService.GetAll(term, page, count, order, orderBy, searchBy); ViewBag.TotalRecords = (string.IsNullOrEmpty(term)) ? _labelService.Count : model.Count; return(PartialView(MVC.Admin.Label.Views._DataTable, model)); }
public IList<LabelDataTableModel> GetAll(string term, int page, int count, Order order, LabelOrderBy orderBy, LabelSearchBy searchBy) { IQueryable<Label> selectedLabels = _labels.Include(label => label.Posts).AsQueryable(); if (!string.IsNullOrEmpty(term)) { switch (searchBy) { case LabelSearchBy.Name: selectedLabels = selectedLabels.Where(label => label.Name.Contains(term)).AsQueryable(); break; case LabelSearchBy.Description: selectedLabels = selectedLabels.Where(label => label.Description.Contains(term)).AsQueryable(); break; default: break; } } if (order == Order.Asscending) { switch (orderBy) { case LabelOrderBy.Id: selectedLabels = selectedLabels.OrderBy(label => label.Id).AsQueryable(); break; case LabelOrderBy.Name: selectedLabels = selectedLabels.OrderBy(label => label.Name).AsQueryable(); break; case LabelOrderBy.Description: selectedLabels = selectedLabels.OrderBy(label => label.Description).AsQueryable(); break; case LabelOrderBy.PostCount: selectedLabels = selectedLabels.OrderBy(label => label.Posts.Count).AsQueryable(); break; default: break; } } else { switch (orderBy) { case LabelOrderBy.Id: selectedLabels = selectedLabels.OrderByDescending(label => label.Id).AsQueryable(); break; case LabelOrderBy.Name: selectedLabels = selectedLabels.OrderByDescending(label => label.Name).AsQueryable(); break; case LabelOrderBy.Description: selectedLabels = selectedLabels.OrderByDescending(label => label.Description).AsQueryable(); break; case LabelOrderBy.PostCount: selectedLabels = selectedLabels.OrderByDescending(label => label.Posts.Count).AsQueryable(); break; default: break; } } return selectedLabels.Skip(page * count) .Take(count) .Select( label => new LabelDataTableModel { Id = label.Id, Name = label.Name, Description = label.Description, PostCount = label.Posts.Count }) .ToList(); }
public IList <LabelDataTableModel> GetAll(string term, int page, int count, Order order, LabelOrderBy orderBy, LabelSearchBy searchBy) { IQueryable <Label> selectedLabels = _labels.Include(label => label.Posts).AsQueryable(); if (!string.IsNullOrEmpty(term)) { switch (searchBy) { case LabelSearchBy.Name: selectedLabels = selectedLabels.Where(label => label.Name.Contains(term)).AsQueryable(); break; case LabelSearchBy.Description: selectedLabels = selectedLabels.Where(label => label.Description.Contains(term)).AsQueryable(); break; default: break; } } if (order == Order.Asscending) { switch (orderBy) { case LabelOrderBy.Id: selectedLabels = selectedLabels.OrderBy(label => label.Id).AsQueryable(); break; case LabelOrderBy.Name: selectedLabels = selectedLabels.OrderBy(label => label.Name).AsQueryable(); break; case LabelOrderBy.Description: selectedLabels = selectedLabels.OrderBy(label => label.Description).AsQueryable(); break; case LabelOrderBy.PostCount: selectedLabels = selectedLabels.OrderBy(label => label.Posts.Count).AsQueryable(); break; default: break; } } else { switch (orderBy) { case LabelOrderBy.Id: selectedLabels = selectedLabels.OrderByDescending(label => label.Id).AsQueryable(); break; case LabelOrderBy.Name: selectedLabels = selectedLabels.OrderByDescending(label => label.Name).AsQueryable(); break; case LabelOrderBy.Description: selectedLabels = selectedLabels.OrderByDescending(label => label.Description).AsQueryable(); break; case LabelOrderBy.PostCount: selectedLabels = selectedLabels.OrderByDescending(label => label.Posts.Count).AsQueryable(); break; default: break; } } return (selectedLabels.Skip(page * count) .Take(count) .Select( label => new LabelDataTableModel { Id = label.Id, Name = label.Name, Description = label.Description, PostCount = label.Posts.Count }) .ToList()); }