예제 #1
0
        public async Task <IActionResult> Receipt(Order order)
        {
            var userId    = _userManager.GetUserId(User);
            var lineItems = await _context.GetLineItems(order.CartID);

            decimal cartTotal = lineItems.Sum(li => li.Product.SuggestedDonation * (int)li.Quantity);

            ViewBag.CartTotal = cartTotal;
            order.OrderItems  = lineItems.ToList();
            return(View(order));
        }
예제 #2
0
        /// <summary>
        /// This method views the user's current, unfulfilled cart by grabbing its user ID from the route.
        /// </summary>
        /// <param name="userId">ApplicationUser's string ID</param>
        /// <returns></returns>
        public async Task <IActionResult> Active()
        {
            var userId = _userManager.GetUserId(User);

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

            var cart = await _context.GetCartByUserId(userId);

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

            var li = await _liContext.GetLineItems(cart.ID);

            return(View("Details", li));
        }
예제 #3
0
        /// <summary>
        /// Method to query the db context for cart that belongs to current signed in user where cart order is unfulfilled.
        /// </summary>
        /// <param name="userID">Current user ID</param>
        /// <returns>View that calls this method</returns>
        public async Task <IViewComponentResult> InvokeAsync(string userId)
        {
            ApplicationUser user = await _userContext.Users.FirstOrDefaultAsync(u => u.Id == userId);

            var foundCart = await _context.Carts.FirstOrDefaultAsync(c => c.OrderFulfilled == false && c.User == user);

            if (user != null && foundCart != null)
            {
                Cart cart = await _context.Carts
                            .Include(c => c.LineItems)
                            .Include(c => c.User)
                            .FirstOrDefaultAsync(c => c.User.Id == user.Id && !c.OrderFulfilled);

                var lineItems = await _liContext.GetLineItems(cart.ID);

                decimal cartTotal = lineItems.Sum(li => li.Product.SuggestedDonation * (int)li.Quantity);
                ViewBag.CartTotal = cartTotal;
                return(View(lineItems));
            }

            return(View());
        }
예제 #4
0
        /// <summary>
        /// Returns all line items
        /// </summary>
        /// <returns>Line times view</returns>
        public async Task <IActionResult> Index()
        {
            var lineItems = await _context.GetLineItems();

            return(View(lineItems));
        }