コード例 #1
0
        // GET: Catalogs/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var catalog = await _catalogService.FindAsync(id.Value);

            if (catalog == null)
            {
                return(NotFound());
            }
            return(View(catalog));
        }
コード例 #2
0
        public async Task <ActionResult> Product(string id)
        {
            Product product = await catalogService.FindAsync(id);

            if (product == null)
            {
                return(HttpNotFound());
            }

            return(View(product));
        }
コード例 #3
0
        public async Task <IHttpActionResult> Get(string id)
        {
            Product product = await catalogService.FindAsync(id);

            if (product == null)
            {
                return(NotFound());
            }

            return(Ok(product));
        }
コード例 #4
0
        public async Task <ActionResult> Checkout()
        {
            decimal totalCost = 0;
            Cart    cart      = await shoppingCartService.GetCartAsync();

            ApplicationUser user = userManager.FindById(User.Identity.GetUserId());

            Order order = new Order()
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Address   = user.Address,
                House     = user.House,
                Zip       = user.Zip,
                City      = user.City,
                Email     = user.Email,
                Tax       = financeService.Tax,
                Date      = DateTime.Now
            };

            foreach (CartItem cartItem in cart.Items)
            {
                Product product = await catalogService.FindAsync(cartItem.ProductId);

                order.Items.Add(new OrderItem()
                {
                    ProductId = product.Id,
                    Price     = product.Price,
                    Quantity  = cartItem.Quantity
                });

                totalCost += Convert.ToDecimal(product.Price * cartItem.Quantity);
            }

            Session["CurrentOrder"] = order;
            Session["CartTotal"]    = totalCost;

            return(RedirectToAction("Payment"));
        }
コード例 #5
0
        public async Task FillCartAsync(Cart cart, ICatalogService catalogService, IFinanceService financeService)
        {
            foreach (CartItem item in cart.Items)
            {
                item.Product = await catalogService.FindAsync(item.ProductId);

                item.Total = item.Quantity * item.Product.Price;
            }

            cart.SubTotal = cart.Items.Sum(x => x.Quantity * x.Product.Price);
            cart.Tax      = financeService.Tax;
            cart.TaxTotal = financeService.CalculateTax(cart.SubTotal);
            cart.Total    = cart.SubTotal + cart.TaxTotal;
        }
コード例 #6
0
        public async Task FillCartAsync(Cart cart, ICatalogService catalogService, IFinanceService financeService)
        {
            foreach (CartItem item in cart.Items)
            {
                /// <summary>
                ///     Use the bellow code to properly empty cart when an item that does not exist
                ///         enters the pool of items.
                /// </summary>
                //string productID = "001";
                //item.Product = await catalogService.FindAsync(productID);

                /// <summary>
                ///     Comment below lines out to properly delete all items in cart.
                /// </summary>
                if (item.ProductId.Length < 3)
                {
                    string productId = item.ProductId;
                    productId = productId.PadLeft(3, '0');

                    item.Product = await catalogService.FindAsync(productId);
                }
                else
                {
                    item.Product = await catalogService.FindAsync(item.ProductId);
                }

                if (item.Product != null)
                {
                    item.Total = item.Quantity * item.Product.Price;
                }
            }

            cart.SubTotal = cart.Items.Sum(x => x.Quantity * x.Product.Price);
            cart.Tax      = financeService.Tax;
            cart.TaxTotal = financeService.CalculateTax(cart.SubTotal);
            cart.Total    = cart.SubTotal + cart.TaxTotal;
        }
コード例 #7
0
        public async Task <ActionResult> Checkout()
        {
            Cart cart = await shoppingCartService.GetCartAsync();

            ApplicationUser user = userManager.FindById(User.Identity.GetUserId());

            Order order = new Order()
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Title     = user.Title.Value.ToString(),
                Address   = user.Address,
                House     = user.House,
                Zip       = user.Zip,
                City      = user.City,
                Email     = user.Email,
                Tax       = financeService.Tax,
                Date      = DateTime.Now
            };

            foreach (CartItem cartItem in cart.Items)
            {
                Product product = await catalogService.FindAsync(cartItem.ProductId);

                order.Items.Add(new OrderItem()
                {
                    ProductId = product.Id,
                    Price     = product.Price,
                    Quantity  = cartItem.Quantity
                });
            }
            await erpService.SaveAsync(order);

            await shoppingCartService.EmptyCartAsync(cart);

            return(RedirectToAction("Thanks", new { order.Id }));
        }