/// <summary> /// Main view of the index page and a user can apply a discount /// This is where they can start to put in their shipping info /// </summary> /// <param name="discountCoupon"></param> /// <returns></returns> public async Task <IActionResult> Index(string discountCoupon) { var user = await _userManager.FindByEmailAsync(User.Identity.Name); Basket datBasket = _basketRepo.GetUserBasketByEmail(user.Email).Result; if (datBasket == null || datBasket.BasketItems.Count == 0) { return(RedirectToAction("MyBasket", "Shop")); } CheckoutViewModel datCheckoutVM = new CheckoutViewModel { Basket = datBasket, }; if (!String.IsNullOrEmpty(discountCoupon)) { string upperCaseCoupon = discountCoupon.ToUpper(); if (upperCaseCoupon == "IAMDOGE" || upperCaseCoupon == "ILIKEFATCATS") { datCheckoutVM.DiscountPercent = 20; } if (upperCaseCoupon == "CODEFELLOWS") { datCheckoutVM.DiscountPercent = 10; } datCheckoutVM.DiscountName = upperCaseCoupon; } return(View(datCheckoutVM)); }
public async Task <IActionResult> Add(int?id) { var user = await _userManager.FindByEmailAsync(User.Identity.Name); Product product = _robotoRepo.GetProductById(id).Result; Basket basket = await _basketRepo.GetUserBasketByEmail(user.Email); if (basket == null) { Basket datBasket = new Basket { CustomerEmail = user.Email }; await _basketRepo.CreateBasket(datBasket); } await _basketRepo.AddProductToBasket(user.Email, product); return(RedirectToAction(nameof(MyBasket))); }
/// <summary> /// find the basket connected with a user, which is by their email /// if the basket is empty, give them a new one /// </summary> /// <returns>the datBasket to the view</returns> public async Task <IViewComponentResult> InvokeAsync() { Basket datBasket; var user = await _userManager.FindByEmailAsync(User.Identity.Name); datBasket = _basketRepo.GetUserBasketByEmail(user.Email).Result; if (datBasket == null) { datBasket = new Basket(); } return(View(datBasket)); }