Пример #1
0
 public void GetCartTotals()
 {
     Subtotal      = CartItems.Sum(o => o.Subtotal);
     ShippingTotal = CartItems.Sum(o => o.ShippingCost);
     TaxTotal      = CartItems.Sum(o => o.TaxCost);
     Total         = CartItems.Sum(o => o.CartItemTotal);
 }
Пример #2
0
        public ActionResult Finish(FormCollection form)
        {
            if (CartItems.Count <= 0)
            {
                return(RedirectToAction("Index", "Cart"));
            }
            var order  = new OrderSummary();
            var member = db.MemberShips.First(m => m.Email == User.Identity.Name);

            order.OrderDate = DateTime.Now;
            if (TryUpdateModel(order))
            {
                order.OrderDetails = GetOrderDetails(member);
                order.TotalTax     = CartItems.Sum(item => item.TaxPrice);
                order.Shipping     = member.Role == Role.Premium ? 0 : CartItems.Max(item => item.Shipping);
                order.TotalPrice   = Math.Round(CartItems.Sum(item => item.Price) + order.TotalTax + order.Shipping, 2);
                order.Member       = member;
                order.OrderStatus  = db.OrderStatuses.First(os => os.Id == 1);
                StockOut(order);
                db.Orders.Add(order);
                db.SaveChanges();
                CartItems.Clear();
                TempData["OrderId"] = order.Id;
                SendOrderMail(order);

                CheckAndUpgradeMember(order.Member);

                //Call Pay gateway
                return(RedirectToAction("InitiateCreditTransaction", new { transAmount = order.TotalPrice, orderId = order.Id }));
            }
            return(View("CheckOut"));
        }
Пример #3
0
        public ActionResult Finish(FormCollection form)
        {
            if (CartItems.Count <= 0)
            {
                return(RedirectToAction("Index", "Cart"));
            }
            var order = new OrderHeader();

            order.OrderDate = DateTime.Now;
            if (TryUpdateModel(order))
            {
                order.OrderDetails = GetOrderDetails();
                order.TotalPrice   = CartItems.Sum(item => item.Price);
                order.Member       = db.Members.First(m => m.Email == User.Identity.Name);
                order.OrderStatus  = db.OrderStatuses.First(os => os.Id == 1);
                StockSellOut(order);
                db.Orders.Add(order);
                db.SaveChanges();
                CartItems.Clear();
                TempData["OrderId"] = order.Id;
                SendFinishedOrderMail(order);
                return(RedirectToAction("Finish"));
            }
            return(View("CheckOut"));
        }
Пример #4
0
        public IActionResult OnPostUpdateShoppingCart(int recordId, int count)
        {
            shoppingCart.UpdateCart(recordId, count);
            CartItems  = shoppingCart.GetCartItems();
            TotalCount = CartItems.Sum(c => c.Count);
            Total      = CartItems.Sum(c => c.Count * c.Product.Price);

            return(Page());
        }
Пример #5
0
        public IActionResult OnPostSendOrder()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var items = cartService.GetAll();

            if (!items.Any())
            {
                ModelState.AddModelError("Empty Cart", "You cannot send an order with an empty cart.");
                return(Page());
            }

            var userId     = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var orderItems = items.Select(item => new Domain.OrderItem {
                MealId = item.ItemId, Quantity = item.Quantity
            }).ToList();
            var total = CartItems.Sum(ci => ci.Price * ci.Quantity) * (decimal)discountProvider.GetDiscount();

            cartService.Clear();

            var order = new Order {
                Id          = Guid.NewGuid().ToString(),
                Items       = orderItems,
                UserId      = userId,
                Address     = $"{OrderDetails.Address}, {OrderDetails.PostalCode}.",
                PhoneNumber = OrderDetails.PhoneNumber,
                Date        = DateTime.Now,
                Total       = total,
                Comments    = OrderDetails.Comments
            };

            ordersService.Create(order);

            return(RedirectToPagePermanent("MyOrders"));
        }
Пример #6
0
 public ActionResult UpdateAmount(List <CartItem> updateCartItems)
 {
     Thread.Sleep(1000);
     if (ModelState.IsValid)
     {
         foreach (var item in CartItems)
         {
             var updateCartItem = updateCartItems.FirstOrDefault(newItem => newItem.Id == item.Id);
             if (updateCartItem != null)
             {
                 //若要購買的數量大於存貨,則將購買數量減少至存貨數量
                 if (updateCartItem.Amount > item.Album.Stock)
                 {
                     item.Amount = item.Album.Stock;
                 }
                 else
                 {
                     item.Amount = updateCartItem.Amount;
                 }
             }
         }
         return(Json(
                    new {
             NewCartItems = CartItems.Select(item =>
                                             new {
                 Id = item.Id, Amount = item.Amount,
                 Price = item.Price.ToString("C")
             }),
             Total = CartItems.Sum(i => i.Price).ToString("C")
         }));
     }
     else
     {
         return(Json(new { Error = "更新失敗" }));
     }
 }
Пример #7
0
 public decimal GetValue()
 {
     return(CartItems.Sum(i => i.Quantity * i.Product.Price));
 }
 private void UpdateItemCount()
 {
     _totalItems = CartItems.Sum(i => i.Quantity);
 }
        public void CalculateTotalOrderPrice()
        {
            var sum = CartItems.Sum(s => s.ProductPrice * s.ProductQuantity);

            TotalPrice = Convert.ToDouble(sum);
        }
Пример #10
0
 public ActionResult CartSummary()
 {
     ViewData["CartCount"] = CartItems.Sum(o => o.Amount);
     return(PartialView("CartSummary"));
 }
Пример #11
0
 public int TotalQuantity()
 {
     return(CartItems.Sum(x => x.Quantity));
 }
Пример #12
0
 public void OnGet()
 {
     CartItems  = shoppingCart.GetCartItems();
     TotalCount = CartItems.Sum(c => c.Count);
     Total      = CartItems.Sum(c => c.Count * c.Product.Price);
 }