// GET: Admin/ArticleCategories public async Task <IActionResult> Index(string keyword, string orderby = "importance", string sort = "desc") { var vm = new ArticleCategoryList { Keyword = keyword, OrderBy = orderby, Sort = sort }; var query = _context.ArticleCategories.AsNoTracking().AsQueryable(); if (!string.IsNullOrEmpty(keyword)) { query = query.Where(d => d.Title.Contains(keyword) || d.Description.Contains(keyword)); } var gosort = $"{orderby}_{sort}"; query = gosort switch { "title_asc" => query.OrderBy(s => s.Title), "title_desc" => query.OrderByDescending(s => s.Title), "date_asc" => query.OrderBy(s => s.CreatedDate), "date_desc" => query.OrderByDescending(s => s.CreatedDate), "importance_asc" => query.OrderBy(s => s.Importance), "importance_desc" => query.OrderByDescending(s => s.Importance), _ => query.OrderByDescending(s => s.Id), }; vm.Categories = await query.ProjectTo <ArticleCategoryBVM>(_mapper.ConfigurationProvider).ToListAsync(); return(View(vm)); }
public ActionResult Index(ArticleCategoryList model) { try { var entity = _unitOfWork.ArticleCategoryRepository.Get(); if (entity != null) { model.Items = Mapper.Map <List <ArticleCategoryView> >(entity); return(View(model)); } } catch (Exception ex) { throw new Exception(ex.Message); } return(View(model)); }