mirror of
https://github.com/rudollee/LearningMVC.git
synced 2025-06-07 16:06:21 +00:00
52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using SportsStore.Domain.Abstract;
|
|
using SportsStore.Domain.Entities;
|
|
using SportsStore.WebUI.Models;
|
|
|
|
namespace SportsStore.WebUI.Controllers
|
|
{
|
|
public class ProductController : Controller
|
|
{
|
|
private IProductRepository repository;
|
|
public int PageSize = 4;
|
|
|
|
public ProductController(IProductRepository productRepository)
|
|
{
|
|
this.repository = productRepository;
|
|
}
|
|
|
|
//public ViewResult List()
|
|
//{
|
|
// return View(repository.Products);
|
|
//}
|
|
|
|
public ViewResult List(int page = 1)
|
|
{
|
|
//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,
|
|
ItemsPerPage = PageSize,
|
|
TotalItems = repository.Products.Count()
|
|
}
|
|
};
|
|
|
|
return View(model);
|
|
}
|
|
|
|
}
|
|
} |