Пример #1
0
        /// <summary>
        /// This shows the member specific order. Some information isn't shown because it is sensitive data.
        /// </summary>
        /// <param name="id">The id of the order to view</param>
        /// <returns>The view of the order</returns>
        public async Task <IActionResult> Details(int id)
        {
            var user = await _userManager.GetUserAsync(User);

            var order = await _order.GetOrderById(id);

            if (order.UserID != user.Id)
            {
                return(RedirectToAction("Index", "Home"));
            }
            order.BasketItems = await _item.GetBasketItems(order.BasketID);

            foreach (BasketItem item in order.BasketItems)
            {
                item.Product = await _inventory.GetProductById(item.ProductID);
            }
            return(View(order));
        }
Пример #2
0
        /// <summary>
        /// This would be the first checkout page with the summary of what is in the basket
        /// It is also where you fill out the billing address and all that other information.
        /// If this was a real ecommerce site, we would be asking for your credit card information here as well.
        /// We would NOT be storing it no matter what but we would use it in our next method to process your order.
        /// </summary>
        /// <returns>The checkout page</returns>
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.FindByEmailAsync(User.Identity.Name);

            var basket = await _context.GetBasketById(user);

            var basketItems = await _item.GetBasketItems(basket.ID);

            var order = await _order.GetOrderByBasketId(basket.ID);

            // This makes sure that we have a new order (that it isn't one that has been purchased already)
            if (order == null || order.IsProcessed == true)
            {
                order = new Order
                {
                    UserID     = user.Id,
                    BasketID   = basket.ID,
                    TotalPrice = 0
                };
                foreach (BasketItem item in basketItems)
                {
                    item.Product = await _inventory.GetProductById(item.ProductID);

                    order.TotalPrice += item.Product.Price * item.Quantity;
                }
                order.BasketItems = basketItems;
                await _order.CreateOrder(order);
            }
            // This else is for if there is already an order waiting but it hasn't been completed yet.
            else
            {
                foreach (BasketItem item in basketItems)
                {
                    item.Product = await _inventory.GetProductById(item.ProductID);
                }
                order.BasketItems = basketItems;
            }
            CheckoutViewModel cvm = new CheckoutViewModel()
            {
                Order = order,
            };

            return(View(cvm));
        }
Пример #3
0
        public async Task <IActionResult> Details()
        {
            var user = await _userManager.FindByEmailAsync(User.Identity.Name);

            Basket basket = await _context.GetBasketById(user);

            // This logic makes sure that if the user accesses this page without a basket or with only processed baskets
            // That a basket is created for them and they are assigned that basket.
            if (basket == null || basket.IsProcessed == true)
            {
                await _context.CreateBasket(user);

                basket = await _context.GetBasketById(user);
            }
            basket.BasketItems = await _item.GetBasketItems(basket.ID);

            foreach (BasketItem item in basket.BasketItems)
            {
                item.Product = await _inventory.GetProductById(item.ProductID);
            }
            return(View(basket));
        }