Skip to content

Commit cc2ecf7

Browse files
author
Carlos Cañizares Estévez
committed
Resolve some feedback in catalog section
1 parent 1002356 commit cc2ecf7

17 files changed

Lines changed: 117 additions & 117 deletions

File tree

src/Web/WebMVC/Controllers/CatalogController.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5-
using System.Net.Http;
65
using Microsoft.AspNetCore.Mvc;
7-
using Microsoft.eShopOnContainers.WebMVC.Models;
8-
using Microsoft.Extensions.Options;
9-
using Newtonsoft.Json;
6+
using Microsoft.eShopOnContainers.WebMVC.Models.Pagination;
107
using Microsoft.eShopOnContainers.WebMVC.Services;
118
using Microsoft.eShopOnContainers.WebMVC.Models.CatalogViewModels;
12-
using BikeSharing_Private_Web_Site.Services.Pagination;
9+
1310

1411
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
1512
{
@@ -36,9 +33,9 @@ public async Task<IActionResult> Index(int? BrandFilterApplied, int? TypesFilter
3633
PaginationInfo = new PaginationInfo()
3734
{
3835
ActualPage = page ?? 0,
39-
ItemsPerPage = (_catalogSvc.TotalItems < itemsPage) ? _catalogSvc.TotalItems : itemsPage,
40-
TotalItems = _catalogSvc.TotalItems,
41-
TotalPages = int.Parse(Math.Ceiling(((decimal)_catalogSvc.TotalItems / itemsPage)).ToString())
36+
ItemsPerPage = (catalog.Count < itemsPage) ? catalog.Count : itemsPage,
37+
TotalItems = catalog.Count,
38+
TotalPages = int.Parse(Math.Ceiling(((decimal)catalog.Count / itemsPage)).ToString())
4239
}
4340
};
4441

src/Web/WebMVC/Models/CartViewModels/IndexViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using BikeSharing_Private_Web_Site.Services.Pagination;
2-
using Microsoft.AspNetCore.Mvc.Rendering;
1+
using Microsoft.AspNetCore.Mvc.Rendering;
32
using System;
43
using System.Collections.Generic;
54
using System.Linq;

src/Web/WebMVC/Models/CatalogViewModels/IndexViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using BikeSharing_Private_Web_Site.Services.Pagination;
2-
using Microsoft.AspNetCore.Mvc.Rendering;
1+
using Microsoft.AspNetCore.Mvc.Rendering;
2+
using Microsoft.eShopOnContainers.WebMVC.Models.Pagination;
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;

src/Web/WebMVC/Models/Pagination/PaginationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55

6-
namespace BikeSharing_Private_Web_Site.Services.Pagination
6+
namespace Microsoft.eShopOnContainers.WebMVC.Models.Pagination
77
{
88
public class PaginationInfo
99
{

src/Web/WebMVC/Services/CatalogService.cs

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,60 +18,12 @@ public class CatalogService : ICatalogService
1818
private readonly IOptions<AppSettings> _settings;
1919
private HttpClient _apiClient;
2020
private readonly string _remoteServiceBaseUrl;
21-
private int _totalItems;
22-
23-
public int TotalItems
24-
{
25-
get
26-
{
27-
return _totalItems;
28-
}
29-
}
30-
21+
3122
public CatalogService(IOptions<AppSettings> settings) {
3223
_settings = settings;
3324
_remoteServiceBaseUrl = $"{_settings.Value.CatalogUrl}/api/v1/catalog/";
34-
35-
#region fake data
36-
_items = new List<CatalogItem>()
37-
{
38-
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" },
39-
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" },
40-
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" },
41-
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" },
42-
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" },
43-
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" },
44-
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" },
45-
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" },
46-
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" },
47-
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" },
48-
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" },
49-
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" },
50-
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" },
51-
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" },
52-
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" },
53-
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" },
54-
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" },
55-
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" },
56-
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" },
57-
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" },
58-
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" },
59-
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" },
60-
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" },
61-
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" },
62-
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" },
63-
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" },
64-
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" },
65-
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" }
66-
};
67-
#endregion
6825
}
6926

70-
public CatalogItem GetCatalogItem(string Id)
71-
{
72-
return _items.Where(x => x.Id.Equals(Id)).FirstOrDefault();
73-
}
74-
7527
public async Task<Catalog> GetCatalogItems(int page,int take, int? brand, int? type)
7628
{
7729
_apiClient = new HttpClient();
@@ -89,9 +41,6 @@ public async Task<Catalog> GetCatalogItems(int page,int take, int? brand, int? t
8941
var dataString = await _apiClient.GetStringAsync(catalogUrl);
9042
var response = JsonConvert.DeserializeObject<Catalog>(dataString);
9143

92-
var res = _items;
93-
_totalItems = response.Count;
94-
9544
return response;
9645
}
9746

src/Web/WebMVC/Services/ICatalogService.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
99
{
1010
public interface ICatalogService
1111
{
12-
int TotalItems { get; }
13-
1412
Task<Catalog> GetCatalogItems(int page, int take, int? brand, int? type);
15-
CatalogItem GetCatalogItem(string Id);
1613
Task<IEnumerable<SelectListItem>> GetBrands();
1714
Task<IEnumerable<SelectListItem>> GetTypes();
1815
}

src/Web/WebMVC/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public void ConfigureServices(IServiceCollection services)
5454
services.AddSession();
5555

5656
// Add application services.
57-
services.AddSingleton<ICatalogService, CatalogService>(); //CCE: Once services are integrated, a singleton is not needed we can left transient.
58-
services.AddSingleton<IOrderingService, OrderingService>();
57+
services.AddTransient<ICatalogService, CatalogService>();
58+
services.AddSingleton<IOrderingService, OrderingService>(); //CCE: Once services are integrated, a singleton is not needed we can left transient.
5959
services.AddTransient<IBasketService, BasketService>();
6060

6161
services.Configure<AppSettings>(Configuration);

src/Web/WebMVC/Views/Account/Register.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<li style="margin-right: 65px;"><a asp-area="" asp-controller="Account" asp-action="Login">LOGIN</a></li>
99
</ul>
1010
</div>
11-
<div class="container cart-index-container">
12-
<h4 class="order-create-section-title">CREATE NEW ACCOUNT</h4>
11+
<div class="container register-container">
1312
<form asp-controller="Account" asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
13+
<h4 class="order-create-section-title">CREATE NEW ACCOUNT</h4>
1414
<div asp-validation-summary="All" class="text-danger"></div>
1515
<div class="row">
1616
<div class="form-group col-sm-6">

src/Web/WebMVC/Views/Catalog/Index.cshtml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<img src="~/images/arrow-down.png" class="select-filter-arrow" />
2020
<select asp-for="@Model.TypesFilterApplied" asp-items="@Model.Types" class="select-filter"></select>
2121
</div>
22-
<input type="submit" class="btn-brand btn-brand-small btn-brand-small-filter btn-catalog-apply" value="APPLY" />
22+
<button type="submit" class="btn-brand btn-brand-small btn-brand-small-filter btn-catalog-apply">
23+
<img src="~/images/arrow-right.svg" />
24+
</button>
2325
</form>
2426
</div>
2527
</div>
@@ -28,7 +30,7 @@
2830
@if (Model.CatalogItems.Count() > 0)
2931
{
3032
<div class="container es-pager-top">
31-
@Html.Partial("_pagination", Model)
33+
@Html.Partial("_pagination", Model.PaginationInfo)
3234
</div>
3335
<div class="row">
3436
@foreach (var catalogItem in Model.CatalogItems)
@@ -40,7 +42,7 @@
4042

4143
</div>
4244
<div class="container es-pager-bottom">
43-
@Html.Partial("_pagination", Model)
45+
@Html.Partial("_pagination", Model.PaginationInfo)
4446
</div>
4547
}
4648
else

src/Web/WebMVC/Views/Catalog/_pagination.cshtml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
@model Microsoft.eShopOnContainers.WebMVC.Models.CatalogViewModels.IndexViewModel
1+
@model Microsoft.eShopOnContainers.WebMVC.Models.Pagination.PaginationInfo
22

33
<div class="row">
44
<div class="col-xs-4">
55
<nav>
66
<ul>
77
<li class="page-item">
8-
<a class="text previous @Model.PaginationInfo.Previous" id="Previous"
9-
href="@Url.Action("Index","Catalog", new { page = Model.PaginationInfo.ActualPage -1 })"
8+
<a class="text previous @Model.Previous" id="Previous"
9+
href="@Url.Action("Index","Catalog", new { page = Model.ActualPage -1 })"
1010
aria-label="Previous">
1111
<span>Previous</span>
1212
</a>
1313
</li>
1414
</ul>
1515
</nav>
1616
</div>
17-
<div class="col-xs-4 u-align-center"><span>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)</span></div>
17+
<div class="col-xs-4 u-align-center"><span>Showing @Html.DisplayFor(modelItem => modelItem.ItemsPerPage) of @Html.DisplayFor(modelItem => modelItem.TotalItems) products - Page @(Model.ActualPage + 1) of @Html.DisplayFor(x => x.TotalPages)</span></div>
1818
<div class="col-xs-4">
1919
<nav>
2020
<ul>
2121
<li class="page-item">
22-
<a class="text next @Model.PaginationInfo.Next" id="Next"
23-
href="@Url.Action("Index","Catalog", new { page = Model.PaginationInfo.ActualPage + 1 })"
22+
<a class="text next @Model.Next" id="Next"
23+
href="@Url.Action("Index","Catalog", new { page = Model.ActualPage + 1 })"
2424
aria-label="Next">
2525
<span>Next</span>
2626
</a>

0 commit comments

Comments
 (0)