Example #1
0
        /// <summary>
        /// Provides the Details page with a Checkout object matching the current user and ID from the route
        /// </summary>
        /// <returns>Checkout object</returns>
        public async Task OnGet()
        {
            string   userEmail = User.Identity.Name;
            Checkout checkout  = await _context.GetCheckoutByUserId(userEmail, ID);

            Checkout = await _checkoutProduce.GetCheckout(ID);

            foreach (var item in Checkout)
            {
                item.ProductTotal = item.Quantity * item.Price;
                item.Total        = checkout.Total;
            }
        }
Example #2
0
        public async Task <IActionResult> Checkout(CheckoutViewModel cvm)
        {
            Checkout checkout = await _context.GetCheckoutByUserId(cvm.Email, cvm.ID);

            checkout.Address = cvm.Address;
            checkout.City    = cvm.City;
            checkout.State   = cvm.State;
            checkout.ZipCode = cvm.ZipCode;

            string userEmail = User.Identity.Name;
            var    userRaw   = await _userManager.FindByEmailAsync(userEmail);

            userRaw.Address = cvm.Address;
            userRaw.State   = cvm.State;
            userRaw.City    = cvm.City;
            userRaw.ZipCode = cvm.ZipCode;
            await _userManager.UpdateAsync(userRaw);

            Payment payment  = new Payment(_configuration);
            string  response = payment.Run(cvm);

            if (response == "Payment Successful")
            {
                Basket basket = await _basketcontext.GetBasketByUserId(userRaw.Id);

                var basketProducts = await _basketProduct.GetBasket(basket.ID);

                foreach (var product in basketProducts)
                {
                    await _basketProduct.DeleteBasketProductByID(basket.ID, product.ProductID);
                }
                return(Redirect($"Receipt/{cvm.ID}"));
            }
            else
            {
                return(View(cvm));
            }
        }
Example #3
0
 /// <summary>
 /// Provides the Details page with details of a selected order
 /// </summary>
 /// <returns>Selected checkout object</returns>
 public async Task OnGetAsync()
 {
     Order = await _checkout.GetCheckoutByUserId(UserID, ID);
 }