// GET: Admin public ActionResult Index() { AdminIndexListViewModel indexVM = new AdminIndexListViewModel(); //Get a list of users first, so that the readaction on the dbcontext finishes List <ApplicationUser> users = db.GetAllUsers().ToList(); //Now convert the list using a lookup function for the role name indexVM.IndexUsers = users.Select(user => MapUserToUserViewModel(user)); indexVM.IndexDepartments = db.Departments().ToList(); return(View(indexVM)); }
public ActionResult Index( AdminIndexListViewModel model, int page = 1, string category = null, string firm = null) { ViewBag.Category = category; ViewBag.Firm = firm; var products = productRepo.Products.ToList(); // тут определяем категории и фирмы в фильтре var categories = categoryRepo.Categories.Select(n => n.Name).Distinct().ToList(); var firms = new List <string>(); if (category != null) { firms = products .Where(p => p.Category == category) .Select(p => p.Firm).Distinct().ToList(); } else { firms = products .Select(p => p.Firm).Distinct().ToList(); } // общее количество товара ViewBag.ProductsCount = products.Count; // фильтруем список products = FilterProductList(products, category, firm); // реализуем пагинацию при создании view модели model = new AdminIndexListViewModel { Products = products.Skip((page - 1) * PageSize).Take(PageSize).ToList(), Categories = categories, Firms = firms, PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = products.Count() } }; return(View(model)); }