Consolidate Web and WebRazorPages Projects (#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
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Route("[controller]/[action]")]
|
||||
[Authorize]
|
||||
[Authorize] // Controllers that mainly require Authorization still use Controller/View; other pages use Pages
|
||||
public class AccountController : Controller
|
||||
{
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
@@ -150,7 +150,7 @@ namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
await _signInManager.SignOutAsync();
|
||||
|
||||
return RedirectToAction(nameof(CatalogController.Index), "Catalog");
|
||||
return RedirectToPage("/Index");
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
@@ -186,7 +186,7 @@ namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
if (userId == null || code == null)
|
||||
{
|
||||
return RedirectToAction(nameof(CatalogController.Index), "Catalog");
|
||||
return RedirectToPage("/Index");
|
||||
}
|
||||
var user = await _userManager.FindByIdAsync(userId);
|
||||
if (user == null)
|
||||
@@ -217,7 +217,7 @@ namespace Microsoft.eShopWeb.Web.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction(nameof(CatalogController.Index), "Catalog");
|
||||
return RedirectToPage("/Index");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb.Infrastructure.Identity;
|
||||
using Microsoft.eShopWeb.Web.Interfaces;
|
||||
using Microsoft.eShopWeb.Web.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Route("[controller]/[action]")]
|
||||
public class BasketController : Controller
|
||||
{
|
||||
private readonly IBasketService _basketService;
|
||||
private readonly IUriComposer _uriComposer;
|
||||
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||
private readonly IAppLogger<BasketController> _logger;
|
||||
private readonly IOrderService _orderService;
|
||||
private readonly IBasketViewModelService _basketViewModelService;
|
||||
|
||||
public BasketController(IBasketService basketService,
|
||||
IBasketViewModelService basketViewModelService,
|
||||
IOrderService orderService,
|
||||
IUriComposer uriComposer,
|
||||
SignInManager<ApplicationUser> signInManager,
|
||||
IAppLogger<BasketController> logger)
|
||||
{
|
||||
_basketService = basketService;
|
||||
_uriComposer = uriComposer;
|
||||
_signInManager = signInManager;
|
||||
_logger = logger;
|
||||
_orderService = orderService;
|
||||
_basketViewModelService = basketViewModelService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var basketModel = await GetBasketViewModelAsync();
|
||||
|
||||
return View(basketModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Index(Dictionary<string, int> items)
|
||||
{
|
||||
var basketViewModel = await GetBasketViewModelAsync();
|
||||
await _basketService.SetQuantities(basketViewModel.Id, items);
|
||||
|
||||
return View(await GetBasketViewModelAsync());
|
||||
}
|
||||
|
||||
|
||||
// POST: /Basket/AddToBasket
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddToBasket(CatalogItemViewModel productDetails)
|
||||
{
|
||||
if (productDetails?.Id == null)
|
||||
{
|
||||
return RedirectToAction("Index", "Catalog");
|
||||
}
|
||||
var basketViewModel = await GetBasketViewModelAsync();
|
||||
|
||||
await _basketService.AddItemToBasket(basketViewModel.Id, productDetails.Id, productDetails.Price, 1);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Checkout(Dictionary<string, int> items)
|
||||
{
|
||||
var basketViewModel = await GetBasketViewModelAsync();
|
||||
await _basketService.SetQuantities(basketViewModel.Id, items);
|
||||
|
||||
await _orderService.CreateOrderAsync(basketViewModel.Id, new Address("123 Main St.", "Kent", "OH", "United States", "44240"));
|
||||
|
||||
await _basketService.DeleteBasketAsync(basketViewModel.Id);
|
||||
|
||||
return View("Checkout");
|
||||
}
|
||||
|
||||
private async Task<BasketViewModel> GetBasketViewModelAsync()
|
||||
{
|
||||
if (_signInManager.IsSignedIn(HttpContext.User))
|
||||
{
|
||||
return await _basketViewModelService.GetOrCreateBasketForUser(User.Identity.Name);
|
||||
}
|
||||
string anonymousId = GetOrSetBasketCookie();
|
||||
return await _basketViewModelService.GetOrCreateBasketForUser(anonymousId);
|
||||
}
|
||||
|
||||
private string GetOrSetBasketCookie()
|
||||
{
|
||||
if (Request.Cookies.ContainsKey(Constants.BASKET_COOKIENAME))
|
||||
{
|
||||
return Request.Cookies[Constants.BASKET_COOKIENAME];
|
||||
}
|
||||
string anonymousId = Guid.NewGuid().ToString();
|
||||
var cookieOptions = new CookieOptions();
|
||||
cookieOptions.Expires = DateTime.Today.AddYears(10);
|
||||
Response.Cookies.Append(Constants.BASKET_COOKIENAME, anonymousId, cookieOptions);
|
||||
return anonymousId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopWeb.Web.Services;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Route("")]
|
||||
public class CatalogController : Controller
|
||||
{
|
||||
private readonly ICatalogService _catalogService;
|
||||
|
||||
public CatalogController(ICatalogService catalogService) => _catalogService = catalogService;
|
||||
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Index(int? brandFilterApplied, int? typesFilterApplied, int? page)
|
||||
{
|
||||
var itemsPage = 10;
|
||||
var catalogModel = await _catalogService.GetCatalogItems(page ?? 0, itemsPage, brandFilterApplied, typesFilterApplied);
|
||||
return View(catalogModel);
|
||||
}
|
||||
|
||||
[HttpGet("Error")]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Authorize]
|
||||
[Authorize] // Controllers that mainly require Authorization still use Controller/View; other pages use Pages
|
||||
[Route("[controller]/[action]")]
|
||||
public class ManageController : Controller
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopWeb.Web.Controllers
|
||||
{
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
[Authorize]
|
||||
[Authorize] // Controllers that mainly require Authorization still use Controller/View; other pages use Pages
|
||||
[Route("[controller]/[action]")]
|
||||
public class OrderController : Controller
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user