예제 #1
0
        public async Task <IActionResult> Checkout()
        {
            string userEmail = User.Identity.Name;
            var    userRaw   = await _userManager.FindByEmailAsync(userEmail);

            string userID = userRaw.Id;

            Basket basket = await _basketcontext.GetBasketByUserId(userID);

            List <BasketProductViewModel> basketProducts = await _basketProduct.GetBasket(basket.ID);

            Checkout checkout = new Checkout();

            checkout.UserID    = userEmail;
            checkout.Name      = User.Claims.First(name => name.Type == "FullName").Value;
            checkout.OrderDate = DateTime.Now;
            await _context.CreateCheckoutAsync(checkout);

            foreach (var bp in basketProducts)
            {
                await _checkoutProduct.AddCheckoutProduct(bp.ProductID, bp.Quantity, checkout.ID);

                bp.BasketID     = checkout.ID;
                checkout.Total += Convert.ToDecimal(bp.Quantity) * bp.Price;
                await _context.UpdateCheckoutAsync(checkout);
            }

            CheckoutViewModel checkoutVM = new CheckoutViewModel()
            {
                ID        = checkout.ID,
                Name      = checkout.Name,
                Email     = userEmail,
                Address   = userRaw.Address,
                City      = userRaw.City,
                State     = userRaw.State,
                ZipCode   = userRaw.ZipCode,
                OrderDate = checkout.OrderDate,
                Total     = checkout.Total,
            };

            return(View(checkoutVM));
        }
예제 #2
0
        /// <summary>
        /// Invokes the component view of the user's shopping basket
        /// </summary>
        /// <returns>Component view of basket</returns>
        public async Task <IViewComponentResult> InvokeAsync()
        {
            string userEmail = User.Identity.Name;
            var    userRaw   = await _userManager.FindByEmailAsync(userEmail);

            string userID = userRaw.Id;
            var    basket = await _basket.GetBasketByUserId(userID);

            var products = await _context.GetBasket(basket.ID);

            return(View(products));
        }
예제 #3
0
        public async Task <IActionResult> Index()
        {
            string userEmail = User.Identity.Name;
            var    userRaw   = await _userManager.FindByEmailAsync(userEmail);

            string userID = userRaw.Id;
            var    basket = await _basket.GetBasketByUserId(userID);

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

            return(View(products));
        }