Skip to content

Commit 64e11dd

Browse files
committed
Merge branch 'Dev' of https://github.com/dotnet/eShopOnContainers into Dev
2 parents 853430a + 45bc1f8 commit 64e11dd

69 files changed

Lines changed: 1315 additions & 1461 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Web/WebMVC/Controllers/AccountController.cs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,15 @@ public class AccountController : Controller
1919
{
2020
private readonly UserManager<ApplicationUser> _userManager;
2121
private readonly SignInManager<ApplicationUser> _signInManager;
22-
private readonly IEmailSender _emailSender;
23-
private readonly ISmsSender _smsSender;
2422
private readonly ILogger _logger;
2523

2624
public AccountController(
2725
UserManager<ApplicationUser> userManager,
2826
SignInManager<ApplicationUser> signInManager,
29-
IEmailSender emailSender,
30-
ISmsSender smsSender,
3127
ILoggerFactory loggerFactory)
3228
{
3329
_userManager = userManager;
3430
_signInManager = signInManager;
35-
_emailSender = emailSender;
36-
_smsSender = smsSender;
3731
_logger = loggerFactory.CreateLogger<AccountController>();
3832
}
3933

@@ -151,7 +145,7 @@ public async Task<IActionResult> LogOff()
151145
{
152146
await _signInManager.SignOutAsync();
153147
_logger.LogInformation(4, "User logged out.");
154-
return RedirectToAction(nameof(HomeController.Index), "Home");
148+
return RedirectToAction(nameof(CatalogController.Index), "Catalog");
155149
}
156150

157151
//
@@ -368,44 +362,6 @@ public async Task<ActionResult> SendCode(string returnUrl = null, bool rememberM
368362
return View(new SendCodeViewModel { Providers = factorOptions, ReturnUrl = returnUrl, RememberMe = rememberMe });
369363
}
370364

371-
//
372-
// POST: /Account/SendCode
373-
[HttpPost]
374-
[AllowAnonymous]
375-
[ValidateAntiForgeryToken]
376-
public async Task<IActionResult> SendCode(SendCodeViewModel model)
377-
{
378-
if (!ModelState.IsValid)
379-
{
380-
return View();
381-
}
382-
383-
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
384-
if (user == null)
385-
{
386-
return View("Error");
387-
}
388-
389-
// Generate the token and send it
390-
var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);
391-
if (string.IsNullOrWhiteSpace(code))
392-
{
393-
return View("Error");
394-
}
395-
396-
var message = "Your security code is: " + code;
397-
if (model.SelectedProvider == "Email")
398-
{
399-
await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code", message);
400-
}
401-
else if (model.SelectedProvider == "Phone")
402-
{
403-
await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
404-
}
405-
406-
return RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe });
407-
}
408-
409365
//
410366
// GET: /Account/VerifyCode
411367
[HttpGet]
@@ -476,7 +432,7 @@ private IActionResult RedirectToLocal(string returnUrl)
476432
}
477433
else
478434
{
479-
return RedirectToAction(nameof(HomeController.Index), "Home");
435+
return RedirectToAction(nameof(CatalogController.Index), "Catalog");
480436
}
481437
}
482438

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Identity;
7+
using Microsoft.eShopOnContainers.WebMVC.Services;
8+
using Microsoft.eShopOnContainers.WebMVC.Models;
9+
using Microsoft.AspNetCore.Authorization;
10+
11+
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
12+
{
13+
[Authorize]
14+
public class CartController : Controller
15+
{
16+
private readonly UserManager<ApplicationUser> _userManager;
17+
private readonly IBasketService _basketSvc;
18+
private readonly ICatalogService _catalogSvc;
19+
20+
public CartController(IBasketService basketSvc, ICatalogService catalogSvc, UserManager<ApplicationUser> userManager)
21+
{
22+
_userManager = userManager;
23+
_basketSvc = basketSvc;
24+
_catalogSvc = catalogSvc;
25+
}
26+
27+
public async Task<IActionResult> Index()
28+
{
29+
var user = await _userManager.GetUserAsync(HttpContext.User);
30+
var vm = _basketSvc.GetBasket(user);
31+
32+
return View(vm);
33+
}
34+
35+
36+
[HttpPost]
37+
public async Task<IActionResult> Index(Dictionary<string, int> quantities, string action)
38+
{
39+
var user = await _userManager.GetUserAsync(HttpContext.User);
40+
var basket = _basketSvc.SetQuantities(user, quantities);
41+
var vm = _basketSvc.UpdateBasket(basket);
42+
43+
if (action == "[ Checkout ]")
44+
{
45+
var order = _basketSvc.MapBasketToOrder(basket);
46+
return RedirectToAction("Create", "Order");
47+
}
48+
49+
return View(vm);
50+
}
51+
52+
public async Task<IActionResult> AddToCart(string productId)
53+
{
54+
var user = await _userManager.GetUserAsync(HttpContext.User);
55+
var productDetails = _catalogSvc.GetCatalogItem(productId);
56+
var product = new BasketItem()
57+
{
58+
Id = Guid.NewGuid().ToString(),
59+
Quantity = 1,
60+
ProductName = productDetails.Name,
61+
PictureUrl = productDetails.PictureUrl,
62+
UnitPrice = productDetails.Price,
63+
ProductId = productId
64+
};
65+
_basketSvc.AddItemToBasket(user, product);
66+
return RedirectToAction("Index", "Catalog");
67+
}
68+
}
69+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using System.Net.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.eShopOnContainers.WebMVC.Models;
8+
using Microsoft.Extensions.Options;
9+
using Newtonsoft.Json;
10+
using Microsoft.eShopOnContainers.WebMVC.Services;
11+
using Microsoft.eShopOnContainers.WebMVC.Models.CatalogViewModels;
12+
using BikeSharing_Private_Web_Site.Services.Pagination;
13+
14+
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
15+
{
16+
public class CatalogController : Controller
17+
{
18+
private ICatalogService _catalogSvc;
19+
20+
public CatalogController(ICatalogService catalogSvc)
21+
{
22+
_catalogSvc = catalogSvc;
23+
}
24+
25+
public async Task<IActionResult> Index(int? BrandFilterApplied, int? TypesFilterApplied, int? page)
26+
{
27+
var vm = new IndexViewModel()
28+
{
29+
CatalogItems = await _catalogSvc.GetCatalogItems(6 * (page ?? 0), 6),
30+
Brands = _catalogSvc.GetBrands(),
31+
Types = _catalogSvc.GetTypes(),
32+
BrandFilterApplied = BrandFilterApplied ?? 0,
33+
TypesFilterApplied = TypesFilterApplied ?? 0,
34+
PaginationInfo = new PaginationInfo()
35+
{
36+
ActualPage = page ?? 0,
37+
ItemsPerPage = 6,
38+
TotalItems = _catalogSvc.TotalItems,
39+
TotalPages = int.Parse(Math.Round(((decimal)_catalogSvc.TotalItems / 6), MidpointRounding.AwayFromZero).ToString())
40+
}
41+
};
42+
43+
vm.PaginationInfo.Next = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
44+
vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
45+
46+
return View(vm);
47+
}
48+
49+
public IActionResult Error()
50+
{
51+
return View();
52+
}
53+
}
54+
}
55+

src/Web/WebMVC/Controllers/HomeController.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)