diff --git a/src/Web/WebMVC/Controllers/CatalogController.cs b/src/Web/WebMVC/Controllers/CatalogController.cs index 640a755b1..8c916a0e4 100644 --- a/src/Web/WebMVC/Controllers/CatalogController.cs +++ b/src/Web/WebMVC/Controllers/CatalogController.cs @@ -2,14 +2,11 @@ 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.Models.Pagination; using Microsoft.eShopOnContainers.WebMVC.Services; using Microsoft.eShopOnContainers.WebMVC.Models.CatalogViewModels; -using BikeSharing_Private_Web_Site.Services.Pagination; + namespace Microsoft.eShopOnContainers.WebMVC.Controllers { @@ -36,9 +33,9 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers PaginationInfo = new PaginationInfo() { ActualPage = page ?? 0, - ItemsPerPage = (_catalogSvc.TotalItems < itemsPage) ? _catalogSvc.TotalItems : itemsPage, - TotalItems = _catalogSvc.TotalItems, - TotalPages = int.Parse(Math.Ceiling(((decimal)_catalogSvc.TotalItems / itemsPage)).ToString()) + ItemsPerPage = (catalog.Count < itemsPage) ? catalog.Count : itemsPage, + TotalItems = catalog.Count, + TotalPages = int.Parse(Math.Ceiling(((decimal)catalog.Count / itemsPage)).ToString()) } }; diff --git a/src/Web/WebMVC/Models/CartViewModels/IndexViewModel.cs b/src/Web/WebMVC/Models/CartViewModels/IndexViewModel.cs index 142dfc6a0..f7acb6612 100644 --- a/src/Web/WebMVC/Models/CartViewModels/IndexViewModel.cs +++ b/src/Web/WebMVC/Models/CartViewModels/IndexViewModel.cs @@ -1,5 +1,4 @@ -using BikeSharing_Private_Web_Site.Services.Pagination; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.Rendering; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Web/WebMVC/Models/CatalogViewModels/IndexViewModel.cs b/src/Web/WebMVC/Models/CatalogViewModels/IndexViewModel.cs index 3c0cc8e78..395c66cdd 100644 --- a/src/Web/WebMVC/Models/CatalogViewModels/IndexViewModel.cs +++ b/src/Web/WebMVC/Models/CatalogViewModels/IndexViewModel.cs @@ -1,5 +1,5 @@ -using BikeSharing_Private_Web_Site.Services.Pagination; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.eShopOnContainers.WebMVC.Models.Pagination; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Web/WebMVC/Models/Pagination/PaginationInfo.cs b/src/Web/WebMVC/Models/Pagination/PaginationInfo.cs index 3baffa560..27eba53fe 100644 --- a/src/Web/WebMVC/Models/Pagination/PaginationInfo.cs +++ b/src/Web/WebMVC/Models/Pagination/PaginationInfo.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace BikeSharing_Private_Web_Site.Services.Pagination +namespace Microsoft.eShopOnContainers.WebMVC.Models.Pagination { public class PaginationInfo { diff --git a/src/Web/WebMVC/Services/CatalogService.cs b/src/Web/WebMVC/Services/CatalogService.cs index 55a18ce75..7da54f84f 100644 --- a/src/Web/WebMVC/Services/CatalogService.cs +++ b/src/Web/WebMVC/Services/CatalogService.cs @@ -18,60 +18,12 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services private readonly IOptions _settings; private HttpClient _apiClient; private readonly string _remoteServiceBaseUrl; - private int _totalItems; - - public int TotalItems - { - get - { - return _totalItems; - } - } - + public CatalogService(IOptions settings) { _settings = settings; _remoteServiceBaseUrl = $"{_settings.Value.CatalogUrl}/api/v1/catalog/"; - - #region fake data - _items = new List() - { - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Cupt Black & White Mug", Name = "Cupt Black & White Mug", Price= 17, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=CuptBlack&WhiteMug" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.PrismWhiteT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = decimal.Parse("19.5"), PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.NETBotBlack" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Cupt Black & White Mug", Name = "Cupt Black & White Mug", Price= 17, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=CuptBlack&WhiteMug" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.PrismWhiteT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = decimal.Parse("19.5"), PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.NETBotBlack" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Cupt Black & White Mug", Name = "Cupt Black & White Mug", Price= 17, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=CuptBlack&WhiteMug" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.PrismWhiteT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = decimal.Parse("19.5"), PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.NETBotBlack" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Cupt Black & White Mug", Name = "Cupt Black & White Mug", Price= 17, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=CuptBlack&WhiteMug" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.PrismWhiteT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = decimal.Parse("19.5"), PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.NETBotBlack" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Cupt Black & White Mug", Name = "Cupt Black & White Mug", Price= 17, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=CuptBlack&WhiteMug" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.PrismWhiteT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = decimal.Parse("19.5"), PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.NETBotBlack" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Cupt Black & White Mug", Name = "Cupt Black & White Mug", Price= 17, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=CuptBlack&WhiteMug" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.PrismWhiteT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = decimal.Parse("19.5"), PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.NETBotBlack" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Cupt Black & White Mug", Name = "Cupt Black & White Mug", Price= 17, PictureUri = "https://fakeimg.pl/370x240/EEEEEE/000/?text=CuptBlack&WhiteMug" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.PrismWhiteT-Shirt" }, - new CatalogItem() { Id = Guid.NewGuid().ToString(), Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = decimal.Parse("19.5"), PictureUri = "http://fakeimg.pl/370x240/EEEEEE/000/?text=.NETBotBlack" } - }; - #endregion } - public CatalogItem GetCatalogItem(string Id) - { - return _items.Where(x => x.Id.Equals(Id)).FirstOrDefault(); - } - public async Task GetCatalogItems(int page,int take, int? brand, int? type) { _apiClient = new HttpClient(); @@ -89,9 +41,6 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services var dataString = await _apiClient.GetStringAsync(catalogUrl); var response = JsonConvert.DeserializeObject(dataString); - var res = _items; - _totalItems = response.Count; - return response; } diff --git a/src/Web/WebMVC/Services/ICatalogService.cs b/src/Web/WebMVC/Services/ICatalogService.cs index f6ca7c819..1abac2390 100644 --- a/src/Web/WebMVC/Services/ICatalogService.cs +++ b/src/Web/WebMVC/Services/ICatalogService.cs @@ -9,10 +9,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services { public interface ICatalogService { - int TotalItems { get; } - Task GetCatalogItems(int page, int take, int? brand, int? type); - CatalogItem GetCatalogItem(string Id); Task> GetBrands(); Task> GetTypes(); } diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index 5b03228d4..130ea8872 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -54,8 +54,8 @@ namespace Microsoft.eShopOnContainers.WebMVC services.AddSession(); // Add application services. - services.AddSingleton(); //CCE: Once services are integrated, a singleton is not needed we can left transient. - services.AddSingleton(); + services.AddTransient(); + services.AddSingleton(); //CCE: Once services are integrated, a singleton is not needed we can left transient. services.AddTransient(); services.Configure(Configuration); diff --git a/src/Web/WebMVC/Views/Account/Register.cshtml b/src/Web/WebMVC/Views/Account/Register.cshtml index 721dc4440..74a417e86 100644 --- a/src/Web/WebMVC/Views/Account/Register.cshtml +++ b/src/Web/WebMVC/Views/Account/Register.cshtml @@ -8,9 +8,9 @@
  • LOGIN
  • -
    -

    CREATE NEW ACCOUNT

    +
    +

    CREATE NEW ACCOUNT

    diff --git a/src/Web/WebMVC/Views/Catalog/Index.cshtml b/src/Web/WebMVC/Views/Catalog/Index.cshtml index eaec34349..cc2223b33 100644 --- a/src/Web/WebMVC/Views/Catalog/Index.cshtml +++ b/src/Web/WebMVC/Views/Catalog/Index.cshtml @@ -19,7 +19,9 @@
    - +
    @@ -28,7 +30,7 @@ @if (Model.CatalogItems.Count() > 0) {
    - @Html.Partial("_pagination", Model) + @Html.Partial("_pagination", Model.PaginationInfo)
    @foreach (var catalogItem in Model.CatalogItems) @@ -40,7 +42,7 @@
    - @Html.Partial("_pagination", Model) + @Html.Partial("_pagination", Model.PaginationInfo)
    } else diff --git a/src/Web/WebMVC/Views/Catalog/_pagination.cshtml b/src/Web/WebMVC/Views/Catalog/_pagination.cshtml index 50acda679..1177e84c5 100644 --- a/src/Web/WebMVC/Views/Catalog/_pagination.cshtml +++ b/src/Web/WebMVC/Views/Catalog/_pagination.cshtml @@ -1,12 +1,12 @@ -@model Microsoft.eShopOnContainers.WebMVC.Models.CatalogViewModels.IndexViewModel +@model Microsoft.eShopOnContainers.WebMVC.Models.Pagination.PaginationInfo
    -
    Showing @Html.DisplayFor(modelItem => modelItem.PaginationInfo.ItemsPerPage) of @Html.DisplayFor(modelItem => modelItem.PaginationInfo.TotalItems) products - Page @(Model.PaginationInfo.ActualPage + 1) of @Html.DisplayFor(x => x.PaginationInfo.TotalPages)
    +
    Showing @Html.DisplayFor(modelItem => modelItem.ItemsPerPage) of @Html.DisplayFor(modelItem => modelItem.TotalItems) products - Page @(Model.ActualPage + 1) of @Html.DisplayFor(x => x.TotalPages)