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.
Consolidate Web and WebRazorPages Projects (dotnet-architecture#192)
* Moved Privacy, Home page to Razor Pages * Migrating Basket from RazorPages to Web. * Removed BasketController; refactored viewmodels * Moved BasketComponent into Pages/Shared Added auth rules to Startup for Pages Added notes to controllers about Pages usage. * Fixed broken my orders test Consolidated Functional Tests * Fixed logo link to home page Fixed Order Detail Total $ format
- Loading branch information
Showing
42 changed files
with
429 additions
and
430 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
src/Web/ViewModels/BasketItemViewModel.cs → src/Web/Pages/Basket/BasketItemViewModel.cs
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; | ||
using Microsoft.eShopWeb.ApplicationCore.Interfaces; | ||
using Microsoft.eShopWeb.Infrastructure.Identity; | ||
using Microsoft.eShopWeb.Web.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.eShopWeb.Web.Pages.Basket | ||
{ | ||
public class CheckoutModel : PageModel | ||
{ | ||
private readonly IBasketService _basketService; | ||
private readonly IUriComposer _uriComposer; | ||
private readonly SignInManager<ApplicationUser> _signInManager; | ||
private readonly IOrderService _orderService; | ||
private string _username = null; | ||
private readonly IBasketViewModelService _basketViewModelService; | ||
|
||
public CheckoutModel(IBasketService basketService, | ||
IBasketViewModelService basketViewModelService, | ||
IUriComposer uriComposer, | ||
SignInManager<ApplicationUser> signInManager, | ||
IOrderService orderService) | ||
{ | ||
_basketService = basketService; | ||
_uriComposer = uriComposer; | ||
_signInManager = signInManager; | ||
_orderService = orderService; | ||
_basketViewModelService = basketViewModelService; | ||
} | ||
|
||
public BasketViewModel BasketModel { get; set; } = new BasketViewModel(); | ||
|
||
public void OnGet() | ||
{ | ||
} | ||
|
||
public async Task<IActionResult> OnPost(Dictionary<string, int> items) | ||
{ | ||
await SetBasketModelAsync(); | ||
|
||
await _basketService.SetQuantities(BasketModel.Id, items); | ||
|
||
await _orderService.CreateOrderAsync(BasketModel.Id, new Address("123 Main St.", "Kent", "OH", "United States", "44240")); | ||
|
||
await _basketService.DeleteBasketAsync(BasketModel.Id); | ||
|
||
return RedirectToPage(); | ||
} | ||
|
||
private async Task SetBasketModelAsync() | ||
{ | ||
if (_signInManager.IsSignedIn(HttpContext.User)) | ||
{ | ||
BasketModel = await _basketViewModelService.GetOrCreateBasketForUser(User.Identity.Name); | ||
} | ||
else | ||
{ | ||
GetOrSetBasketCookieAndUserName(); | ||
BasketModel = await _basketViewModelService.GetOrCreateBasketForUser(_username); | ||
} | ||
} | ||
|
||
private void GetOrSetBasketCookieAndUserName() | ||
{ | ||
if (Request.Cookies.ContainsKey(Constants.BASKET_COOKIENAME)) | ||
{ | ||
_username = Request.Cookies[Constants.BASKET_COOKIENAME]; | ||
} | ||
if (_username != null) return; | ||
|
||
_username = Guid.NewGuid().ToString(); | ||
var cookieOptions = new CookieOptions(); | ||
cookieOptions.Expires = DateTime.Today.AddYears(10); | ||
Response.Cookies.Append(Constants.BASKET_COOKIENAME, _username, cookieOptions); | ||
} | ||
} | ||
} |
Oops, something went wrong.