public ActionResult List(int page = 1) { var products = repository.Products.OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize); var model = new ProductsListViewModel { Products = products, PagingInfo = new PagingInfo { CurrentPage = page, TotalItems = repository.Products.Count(), ItemsPerPage = PageSize } }; return View(model); }
private void PaginationAssert(ProductsListViewModel result) { Product[] products = result.Products.ToArray(); Assert.IsTrue(products.Length == 2); Assert.AreEqual(products[0].Name, "P4"); Assert.AreEqual(products[1].Name, "P5"); }
public ViewResult List(string category, int page = 1) { //_logger.LogInfo("Logging from the List Controller!!"); var viewModel = new ProductsListViewModel { Products = repository.Products .Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = repository.Products.Count() }, CurrentCategory = category }; return View(viewModel); //return View(repository.Products // .OrderBy(p => p.ProductID) // .Skip((page - 1) * PageSize) // .Take(PageSize)); }
public ViewResult List(string category, int page = 1) { ProductsListViewModel model = new ProductsListViewModel { Products = repository.Products .Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductId) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ? repository.Products.Count() : repository.Products.Where(p => p.Category == category).Count() }, CurrentCategory = category }; return View(model); }
// GET: Product public ActionResult List(string category, int page=1) { ProductsListViewModel model = new ProductsListViewModel(); int pageSize = 2; int count; if (category != null) { model.Products = productRepository.Products.Where(p => p.Category == category).Skip((page - 1) * pageSize).Take(pageSize); ViewBag.PageCount = Math.Ceiling((double)productRepository.Products.Where(p => p.Category == category).Count() / pageSize); count = productRepository.Products.Where(p => p.Category == category).Count(); } else { model.Products = productRepository.Products.Skip((page - 1) * pageSize).Take(pageSize); ViewBag.PageCount = Math.Ceiling((double)productRepository.Products.Count() / pageSize); count = productRepository.Products.Count(); } //return View(rep.Products); //model.Products = productRepository.Products.Skip((page - 1) * pageSize).Take(pageSize); model.Category = category; model.pageInfo = new HTMLHelpers.PageInfo() { PageSize = 2, NumProducts = count, CurrentPage=page }; return View(model); }
public ViewResult List(string category, int page = 1) { //return View(productRep.Products // .OrderBy(p => p.ProductID) // .Skip((page - 1) * PageSize) // .Take(PageSize) // ); ProductsListViewModel viewModel = new ProductsListViewModel { Products = productRep.Products .Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ? productRep.Products.Count() : productRep.Products.Where(e => e.Category == category).Count() }, CurrentCategory = category }; return View(viewModel); }
private void PageLinkAssert(ProductsListViewModel result) { PagingInfo pageInfo = result.PagingInfo; Assert.AreEqual(pageInfo.CurrentPage, 2); Assert.AreEqual(pageInfo.ItemsPerPage, 3); Assert.AreEqual(pageInfo.TotalItems, 5); Assert.AreEqual(pageInfo.TotalPages, 2); }
// GET: Product public ViewResult List(int page=1) { ProductsListViewModel model = new ProductsListViewModel(); model.Products = repository.Products.OrderBy(p => p.ProductID).Skip(pageSize * (page - 1)).Take(pageSize); model.PagingInfo = new PagingInfo() { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = repository.Products.Count() }; return View(model); }
public ViewResult Index(Int32 page = 1) { IQueryable<Product> selectedProducts = _repository.Products.OrderBy(p => p.Name) .Skip((page - 1) * _pageSize).Take(_pageSize); ProductsListViewModel model = new ProductsListViewModel { Products = selectedProducts, PagingInfo = new PagingInfo { ItemsPerPage = _pageSize, CurrentPage = page, TotalItems = _repository.Products.Count() } }; return View(model); }
public ViewResult List(string category, int page = 1) { var productsToShow = (category == null) ? productsRepository.Products : productsRepository.Products.Where(x => x.Category == category); var viewModel = new ProductsListViewModel { Products = productsToShow.Skip((page-1)*PageSize).Take(PageSize).ToList(), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = productsToShow.Count() }, CurrentCategory = category }; return View(viewModel); // Passed to view as ViewData.Model (or simply Model) }
public ViewResult List(string category, int page=1) { var pageInfo = new PageInfo { CurrentPage = page, TotalItems = category==null? _repository.Products.Count() : _repository.Products.Where(p => p.Category.CategoryName == category).Count(), ItemsPerPage = PageSize }; if (page < 1 || page > pageInfo.TotalPages) { pageInfo.CurrentPage = 1; } ProductsListViewModel viewModel = new ProductsListViewModel { Products = _repository.Products.Where(p => category==null || p.Category.CategoryName.Replace("/"," ")==category).OrderBy(p => p.ProductID).Skip((pageInfo.CurrentPage - 1) * PageSize).Take(PageSize), PageInfo = pageInfo, CurrentCategory = category }; return View(viewModel); }
public ViewResult List(string Category, int Page = 1) { ProductsListViewModel pvm = new ProductsListViewModel { Products = repo.Products .Where(p=> Category == null || p.Category == Category) .OrderBy(p => p.ProductID) .Skip((Page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = Page, ItemsPerPage = PageSize, TotalItems = (Category == null) ? repo.Products.Count() : repo.Products.Where(p=>p.Category == Category).Count() }, CurrentCategory = Category }; return View(pvm); }
public ViewResult List(String category, Int32 page = 1) { ViewBag.EmptyStore = _repository.Products.Count() == 0; var selectedProducts = _repository.Products.Where(p => category == null || p.Category == category); ProductsListViewModel viewModel = new ProductsListViewModel { Products = selectedProducts.OrderBy(p => p.ProductID) .Skip((page - 1) * _pageSize) .Take(_pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = _pageSize, TotalItems = selectedProducts.Count() }, CurrentCategory = category }; return View(viewModel); }
public ViewResult List(string category, [DefaultValue(1)] int page) { var productsToShow = (category==null) ? productsRepository.Products : productsRepository.Products.Where(x=>x.Category == category); var viewModel = new ProductsListViewModel { Products = productsToShow.Skip((page - 1) * PageSize) .Take(PageSize) .ToList() , PagingInfo = new PagingInfo{ CurrentPage = page , ItemsPerPage = PageSize , TotalItems = productsToShow.Count() } , CurrentCategory = category }; return View(viewModel); }
/*public ActionResult List(int page = 1) { ProductsListViewModel viewModel = new ProductsListViewModel { Products = repository.Products .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = repository.Products.Count() } }; return View(viewModel); }*/ public ActionResult List(string category,int page = 1) { ProductsListViewModel viewModel = new ProductsListViewModel { Products = repository.Products .Where(x=>x.Category == category || x.Category == null) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = repository.Products.Where(x => x.Category == category || x.Category == null).Count() }, CurrentCategory = category }; return View(viewModel); }
//public ViewResult List() //{ // return View(repository.Products); //} //public ViewResult List(int page=1) //{ // ProductsListViewModel viewModel = new ProductsListViewModel() // { // Products = // repository.Products.OrderBy(p => p.ProductID).Skip((page - 1)* // PageSize). // Take(PageSize), // PagingInfo = // new PagingInfo() // { // CurrentPage = page, // ItemsPerPage = PageSize, // TotalItems = repository.Products.Count() // } // }; // return View(viewModel); //} public ViewResult List(string category, int page=1) { var products = repository.Products.Where(p => string.IsNullOrEmpty(category) || p.Category == category).OrderBy(p => p.ProductID); ProductsListViewModel viewModel = new ProductsListViewModel() { Products = products.Skip((page - 1)*PageSize).Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = products.Count() }, CurrentCategory = category }; return View(viewModel); }
public ViewResult List(string Category, int page = 1) { var query = repository.Products; if (!string.IsNullOrWhiteSpace(Category)) query = query.Where(x => x.Category == Category); ProductsListViewModel model = new ProductsListViewModel { Products = query .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = query.Count() }, CurrentCategory = Category }; return View(model); }
public ViewResult List(string category, int page = 1) { var model = new ProductsListViewModel(); model.Products = _repository.Products .Where(x => category == null || x.Category == category) .OrderBy(x => x.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize); model.PagingInfo = new PagingInfo(); model.PagingInfo.CurrentPage = page; model.PagingInfo.ItemsPerPage = PageSize; if (category == null) model.PagingInfo.TotalItems = _repository.Products.Count(); else model.PagingInfo.TotalItems = _repository.Products.Count(x => x.Category == category); model.CurrentCategory = category; return View(model); }
public ViewResult List(string category, int page = 1) { ProductsListViewModel viewModel = new ProductsListViewModel(); viewModel.Products = repository.Products .Where(w => category == null || w.Category == category) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize); viewModel.PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = repository.Products.Where( w=> category == null || w.Category == category).Count() }; viewModel.CurrentCategory = category; return View(viewModel); }
public ViewResult List(string category, int page = 1) { //return View(_repository.Products); //return View(_repository.Products. // OrderBy(p => p.ProductID) // .Skip((page - 1) * PageSize) // .Take(PageSize)); //ProductsListViewModel model = new ProductsListViewModel { // Products = _repository.Products // .OrderBy(p => p.ProductID) // .Skip((page - 1) * PageSize) // .Take(PageSize), // PagingInfo = new PagingInfo { // CurrentPage = page, // ItemPerPage = PageSize, // TotalItems = _repository.Products.Count() // }, //}; ProductsListViewModel model = new ProductsListViewModel { Products = _repository.Products .Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ? _repository.Products.Count() : _repository.Products.Where(e => e.Category == category).Count() }, CurrentCategory = category }; return View(model); }
public ViewResult List(string category, int page=1) { ProductsListViewModel model = new ProductsListViewModel { CurrentCategory=category }; if (string.IsNullOrEmpty(category)) { model.Products = repositroy.Products.OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize); } else { model.Products = repositroy.Products.Where(p => p.Category == category).OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize); } model.PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = string.IsNullOrEmpty(category) ? repositroy.Products.Count() : repositroy.Products.Where(x=>x.Category==category).Count() }; return View(model); //return View(repositroy.Products.OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize)); }
public PartialViewResult ProductList(string category, int page = 1) { if (category == "Home") { category = null; } ProductsListViewModel viewModel = new ProductsListViewModel { Products = repository.Products.Where(p => category == null || p.Category.Name == category) .OrderBy(p => p.ProductID).Skip((page - 1) * PageSize).Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ? repository.Products.Count() : repository.Products.Where(e => e.Category.Name == category).Count() }, CurrentCategory = category }; return PartialView(viewModel); }