forked from dotnet-architecture/eShopOnWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Order Features (dotnet-architecture#47)
* Working on order model binding from checkout page - WIP * Small layout tweaks (dotnet-architecture#43) * Updating quantities implemented. * Fixed basket widget count
- Loading branch information
Showing
9 changed files
with
188 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,52 @@ | ||
using ApplicationCore.Interfaces; | ||
using Infrastructure.Identity; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.eShopWeb.ViewModels; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Web.ViewComponents | ||
{ | ||
public class Basket : ViewComponent | ||
{ | ||
private readonly IBasketService _cartSvc; | ||
private readonly IBasketService _basketService; | ||
private readonly SignInManager<ApplicationUser> _signInManager; | ||
|
||
public Basket(IBasketService cartSvc) => _cartSvc = cartSvc; | ||
public Basket(IBasketService basketService, | ||
SignInManager<ApplicationUser> signInManager) | ||
{ | ||
_basketService = basketService; | ||
_signInManager = signInManager; | ||
} | ||
|
||
public async Task<IViewComponentResult> InvokeAsync(string userName) | ||
{ | ||
var vm = new BasketComponentViewModel(); | ||
var itemsInCart = await ItemsInBasketAsync(userName); | ||
vm.ItemsCount = itemsInCart; | ||
vm.ItemsCount = (await GetBasketViewModelAsync()).Items.Sum(i => i.Quantity); | ||
return View(vm); | ||
} | ||
private async Task<int> ItemsInBasketAsync(string userName) | ||
|
||
private async Task<BasketViewModel> GetBasketViewModelAsync() | ||
{ | ||
if (_signInManager.IsSignedIn(HttpContext.User)) | ||
{ | ||
return await _basketService.GetOrCreateBasketForUser(User.Identity.Name); | ||
} | ||
string anonymousId = GetBasketIdFromCookie(); | ||
if (anonymousId == null) return new BasketViewModel(); | ||
return await _basketService.GetOrCreateBasketForUser(anonymousId); | ||
} | ||
|
||
private string GetBasketIdFromCookie() | ||
{ | ||
var basket = await _cartSvc.GetOrCreateBasketForUser(userName); | ||
return basket.Items.Count; | ||
if (Request.Cookies.ContainsKey(Constants.BASKET_COOKIENAME)) | ||
{ | ||
return Request.Cookies[Constants.BASKET_COOKIENAME]; | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
@model PaginationInfoViewModel | ||
|
||
<div class="esh-pager"> | ||
<div class="container"> | ||
<article class="esh-pager-wrapper row"> | ||
<nav> | ||
<a class="esh-pager-item esh-pager-item--navigable @Model.Previous" | ||
id="Previous" | ||
asp-controller="Catalog" | ||
asp-action="Index" | ||
asp-route-page="@(Model.ActualPage -1)" | ||
aria-label="Previous"> | ||
Previous | ||
</a> | ||
|
||
<span class="esh-pager-item"> | ||
Showing @Model.ItemsPerPage of @Model.TotalItems products - Page @(Model.ActualPage + 1) - @Model.TotalPages | ||
</span> | ||
|
||
<a class="esh-pager-item esh-pager-item--navigable @Model.Next" | ||
id="Next" | ||
asp-controller="Catalog" | ||
asp-action="Index" | ||
asp-route-page="@(Model.ActualPage + 1)" | ||
aria-label="Next"> | ||
Next | ||
</a> | ||
</nav> | ||
</article> | ||
</div> | ||
<div class="container-fluid"> | ||
<article class="esh-pager-wrapper row"> | ||
<nav> | ||
<div class="col-md-2 col-xs-12"> | ||
<a class="esh-pager-item-left esh-pager-item--navigable @Model.Previous" | ||
id="Previous" | ||
asp-controller="Catalog" | ||
asp-action="Index" | ||
asp-route-page="@(Model.ActualPage - 1)" | ||
aria-label="Previous"> | ||
Previous | ||
</a> | ||
</div> | ||
|
||
<div class="col-md-8 col-xs-12"> | ||
<span class="esh-pager-item"> | ||
Showing @Model.ItemsPerPage of @Model.TotalItems products - Page @(Model.ActualPage + 1) - @Model.TotalPages | ||
</span> | ||
</div> | ||
|
||
<div class="col-md-2 col-xs-12"> | ||
<a class="esh-pager-item-right esh-pager-item--navigable @Model.Next" | ||
id="Next" | ||
asp-controller="Catalog" | ||
asp-action="Index" | ||
asp-route-page="@(Model.ActualPage + 1)" | ||
aria-label="Next"> | ||
Next | ||
</a> | ||
</div> | ||
</nav> | ||
</article> | ||
</div> | ||
</div> | ||
|
Oops, something went wrong.