* transfer basket on login

* review page

* unit tests for TransferBasketAsync
This commit is contained in:
yigith
2020-06-25 03:48:23 +03:00
committed by GitHub
parent a4d02d9dad
commit 3b1339787f
12 changed files with 254 additions and 51 deletions

View File

@@ -1,7 +1,7 @@
@page
@model CheckoutModel
@model CheckoutModel
@{
ViewData["Title"] = "Checkout Complete";
ViewData["Title"] = "Checkout";
}
<section class="esh-catalog-hero">
<div class="container">
@@ -10,7 +10,77 @@
</section>
<div class="container">
<h1>Thanks for your Order!</h1>
<h1>Review</h1>
@if (Model.BasketModel.Items.Any())
{
<form asp-page="Checkout" method="post">
<article class="esh-basket-titles row">
<br />
<section class="esh-basket-title col-xs-3">Product</section>
<section class="esh-basket-title col-xs-3 hidden-lg-down"></section>
<section class="esh-basket-title col-xs-2">Price</section>
<section class="esh-basket-title col-xs-2">Quantity</section>
<section class="esh-basket-title col-xs-2">Cost</section>
</article>
<div class="esh-catalog-items row">
<div asp-validation-summary="All" class="text-danger"></div>
@for (int i = 0; i < Model.BasketModel.Items.Count; i++)
{
var item = Model.BasketModel.Items[i];
<article class="esh-basket-items row">
<div>
<section class="esh-basket-item esh-basket-item--middle col-lg-3 hidden-lg-down">
<img class="esh-basket-image" src="@item.PictureUrl" />
</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-3">@item.ProductName</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-2">$ @item.UnitPrice.ToString("N2")</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-2">
<input type="hidden" name="@("Items[" + i + "].Id")" value="@item.Id" />
<input type="hidden" name="@("Items[" + i + "].Quantity")" value="@item.Quantity" />
@item.Quantity
</section>
<section class="esh-basket-item esh-basket-item--middle esh-basket-item--mark col-xs-2">$ @Math.Round(item.Quantity * item.UnitPrice, 2).ToString("N2")</section>
</div>
<div class="row">
<a asp-page="/Index">Continue Shopping...</a>
</div>
</div>
</article>
}
<div class="container">
<article class="esh-basket-titles esh-basket-titles--clean row">
<section class="esh-basket-title col-xs-10"></section>
<section class="esh-basket-title col-xs-2">Total</section>
</article>
<article class="esh-basket-items row">
<section class="esh-basket-item col-xs-10"></section>
<section class="esh-basket-item esh-basket-item--mark col-xs-2">$ @Model.BasketModel.Total().ToString("N2")</section>
</article>
<article class="esh-basket-items row">
<section class="esh-basket-item col-xs-7"></section>
</article>
</div>
<div class="row">
<section class="esh-basket-item col-xs-1">
<a asp-page="Index" class="btn esh-basket-checkout text-white">[ Back ]</a>
</section>
<section class="esh-basket-item col-xs-push-7 col-xs-4 text-right">
<input type="submit" class="btn esh-basket-checkout" value="[ Pay Now ]" />
</section>
</div>
</div>
</form>
}
else
{
<h3 class="esh-catalog-items row">
Basket is empty.
</h3>
<section class="esh-basket-item">
<a asp-page="/Index" class="btn esh-basket-checkout text-white">[ Continue Shopping..]</a>
</section>
}
</div>

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
@@ -14,6 +15,7 @@ using System.Threading.Tasks;
namespace Microsoft.eShopWeb.Web.Pages.Basket
{
[Authorize]
public class CheckoutModel : PageModel
{
private readonly IBasketService _basketService;
@@ -40,13 +42,7 @@ namespace Microsoft.eShopWeb.Web.Pages.Basket
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);
}
await SetBasketModelAsync();
}
public async Task<IActionResult> OnPost(IEnumerable<BasketItemViewModel> items)
@@ -72,7 +68,7 @@ namespace Microsoft.eShopWeb.Web.Pages.Basket
return RedirectToPage("/Basket/Index");
}
return RedirectToPage();
return RedirectToPage("Success");
}
private async Task SetBasketModelAsync()

View File

@@ -27,23 +27,23 @@
@for (int i = 0; i < Model.BasketModel.Items.Count; i++)
{
var item = Model.BasketModel.Items[i];
<article class="esh-basket-items row">
<div>
<section class="esh-basket-item esh-basket-item--middle col-lg-3 hidden-lg-down">
<img class="esh-basket-image" src="@item.PictureUrl" />
</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-3">@item.ProductName</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-2">$ @item.UnitPrice.ToString("N2")</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-2">
<input type="hidden" name="@("Items[" + i + "].Id")" value="@item.Id" />
<input type="number" class="esh-basket-input" min="0" name="@("Items[" + i + "].Quantity")" value="@item.Quantity" />
</section>
<section class="esh-basket-item esh-basket-item--middle esh-basket-item--mark col-xs-2">$ @Math.Round(item.Quantity * item.UnitPrice, 2).ToString("N2")</section>
</div>
<div class="row">
<article class="esh-basket-items row">
<div>
<section class="esh-basket-item esh-basket-item--middle col-lg-3 hidden-lg-down">
<img class="esh-basket-image" src="@item.PictureUrl" />
</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-3">@item.ProductName</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-2">$ @item.UnitPrice.ToString("N2")</section>
<section class="esh-basket-item esh-basket-item--middle col-xs-2">
<input type="hidden" name="@("Items[" + i + "].Id")" value="@item.Id" />
<input type="number" class="esh-basket-input" min="0" name="@("Items[" + i + "].Quantity")" value="@item.Quantity" />
</section>
<section class="esh-basket-item esh-basket-item--middle esh-basket-item--mark col-xs-2">$ @Math.Round(item.Quantity * item.UnitPrice, 2).ToString("N2")</section>
</div>
<div class="row">
</div>
</article>
</div>
</article>
}
<div class="container">
@@ -71,16 +71,7 @@
asp-page-handler="Update">
[ Update ]
</button>
@{
var data = new Dictionary<string, string>
{
{ Constants.BASKET_ID, Model.BasketModel.Id.ToString() },
};
}
<input type="submit" asp-page="Checkout"
class="btn esh-basket-checkout"
asp-all-route-data=data
value="[ Checkout ]" name="action" />
<a asp-page="./Checkout" class="btn esh-basket-checkout">[ Checkout ]</a>
</section>
</div>
</div>
@@ -91,7 +82,7 @@
<h3 class="esh-catalog-items row">
Basket is empty.
</h3>
<section class="esh-basket-item">
<a asp-page="/Index" class="btn esh-basket-checkout text-white">[ Continue Shopping..]</a>
</section>

View File

@@ -0,0 +1,17 @@
@page
@model SuccessModel
@{
ViewData["Title"] = "Checkout Complete";
}
<section class="esh-catalog-hero">
<div class="container">
<img class="esh-catalog-title" src="~/images/main_banner_text.png" />
</div>
</section>
<div class="container">
<h1>Thanks for your Order!</h1>
<a asp-page="/Index">Continue Shopping...</a>
</div>

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Microsoft.eShopWeb.Web.Pages.Basket
{
[Authorize]
public class SuccessModel : PageModel
{
public void OnGet()
{
}
}
}