manage basket checkout after login (#371)
This commit is contained in:
@@ -5,6 +5,7 @@ using Microsoft.eShopWeb.ApplicationCore.Entities;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Ardalis.GuardClauses;
|
using Ardalis.GuardClauses;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
|
||||||
|
using Microsoft.eShopWeb.ApplicationCore.Specifications;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.ApplicationCore.Services
|
namespace Microsoft.eShopWeb.ApplicationCore.Services
|
||||||
{
|
{
|
||||||
@@ -28,7 +29,9 @@ namespace Microsoft.eShopWeb.ApplicationCore.Services
|
|||||||
|
|
||||||
public async Task CreateOrderAsync(int basketId, Address shippingAddress)
|
public async Task CreateOrderAsync(int basketId, Address shippingAddress)
|
||||||
{
|
{
|
||||||
var basket = await _basketRepository.GetByIdAsync(basketId);
|
var basketSpec = new BasketWithItemsSpecification(basketId);
|
||||||
|
var basket = await _basketRepository.FirstOrDefaultAsync(basketSpec);
|
||||||
|
|
||||||
Guard.Against.NullBasket(basketId, basket);
|
Guard.Against.NullBasket(basketId, basket);
|
||||||
var items = new List<OrderItem>();
|
var items = new List<OrderItem>();
|
||||||
foreach (var item in basket.Items)
|
foreach (var item in basket.Items)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
namespace Microsoft.eShopWeb.Web
|
namespace Microsoft.eShopWeb.Web
|
||||||
{
|
{
|
||||||
public static class Constants
|
public static class Constants
|
||||||
{
|
{
|
||||||
public const string BASKET_COOKIENAME = "eShop";
|
public const string BASKET_COOKIENAME = "eShop";
|
||||||
public const int ITEMS_PER_PAGE = 10;
|
public const int ITEMS_PER_PAGE = 10;
|
||||||
public const string DEFAULT_USERNAME = "Guest";
|
public const string DEFAULT_USERNAME = "Guest";
|
||||||
|
public const string BASKET_ID = "BasketId";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,15 @@ namespace Microsoft.eShopWeb.Web.Pages.Basket
|
|||||||
|
|
||||||
public BasketViewModel BasketModel { get; set; } = new BasketViewModel();
|
public BasketViewModel BasketModel { get; set; } = new BasketViewModel();
|
||||||
|
|
||||||
public void OnGet()
|
public async Task OnGet()
|
||||||
{
|
{
|
||||||
|
if (HttpContext.Request.Query.ContainsKey(Constants.BASKET_ID))
|
||||||
|
{
|
||||||
|
var basketId = int.Parse(HttpContext.Request.Query[Constants.BASKET_ID]);
|
||||||
|
await _basketService.TransferBasketAsync(Request.Cookies[Constants.BASKET_COOKIENAME], User.Identity.Name);
|
||||||
|
await _orderService.CreateOrderAsync(basketId, new Address("123 Main St.", "Kent", "OH", "United States", "44240"));
|
||||||
|
await _basketService.DeleteBasketAsync(basketId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPost(Dictionary<string, int> items)
|
public async Task<IActionResult> OnPost(Dictionary<string, int> items)
|
||||||
|
|||||||
@@ -77,8 +77,15 @@
|
|||||||
asp-page-handler="Update">
|
asp-page-handler="Update">
|
||||||
[ Update ]
|
[ Update ]
|
||||||
</button>
|
</button>
|
||||||
|
@{
|
||||||
|
var data = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ Constants.BASKET_ID, Model.BasketModel.Id.ToString() },
|
||||||
|
};
|
||||||
|
}
|
||||||
<input type="submit" asp-page="Checkout"
|
<input type="submit" asp-page="Checkout"
|
||||||
class="btn esh-basket-checkout"
|
class="btn esh-basket-checkout"
|
||||||
|
asp-all-route-data=data
|
||||||
value="[ Checkout ]" name="action" />
|
value="[ Checkout ]" name="action" />
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ namespace Microsoft.eShopWeb.Web
|
|||||||
|
|
||||||
services.AddHttpContextAccessor();
|
services.AddHttpContextAccessor();
|
||||||
|
|
||||||
services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApi.Models.OpenApiInfo { Title = "My API", Version = "v1"}));
|
services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApi.Models.OpenApiInfo { Title = "My API", Version = "v1" }));
|
||||||
|
|
||||||
services.AddHealthChecks();
|
services.AddHealthChecks();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user