56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Net.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.eShopOnContainers.WebMVC.Models;
|
|
using Microsoft.Extensions.Options;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.eShopOnContainers.WebMVC.Services;
|
|
using Microsoft.eShopOnContainers.WebMVC.Models.CatalogViewModels;
|
|
using BikeSharing_Private_Web_Site.Services.Pagination;
|
|
|
|
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
|
{
|
|
public class CatalogController : Controller
|
|
{
|
|
private ICatalogService _catalogSvc;
|
|
|
|
public CatalogController(ICatalogService catalogSvc)
|
|
{
|
|
_catalogSvc = catalogSvc;
|
|
}
|
|
|
|
public async Task<IActionResult> Index(int? BrandFilterApplied, int? TypesFilterApplied, int? page)
|
|
{
|
|
var vm = new IndexViewModel()
|
|
{
|
|
CatalogItems = await _catalogSvc.GetCatalogItems(6 * (page ?? 0), 6),
|
|
Brands = _catalogSvc.GetBrands(),
|
|
Types = _catalogSvc.GetTypes(),
|
|
BrandFilterApplied = BrandFilterApplied ?? 0,
|
|
TypesFilterApplied = TypesFilterApplied ?? 0,
|
|
PaginationInfo = new PaginationInfo()
|
|
{
|
|
ActualPage = page ?? 0,
|
|
ItemsPerPage = 6,
|
|
TotalItems = _catalogSvc.TotalItems,
|
|
TotalPages = int.Parse(Math.Round(((decimal)_catalogSvc.TotalItems / 6), MidpointRounding.AwayFromZero).ToString())
|
|
}
|
|
};
|
|
|
|
vm.PaginationInfo.Next = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
|
|
vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
|
|
|
|
return View(vm);
|
|
}
|
|
|
|
public IActionResult Error()
|
|
{
|
|
return View();
|
|
}
|
|
}
|
|
}
|
|
|