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); }
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")); }
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")); }
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()); }
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")); }
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 = "更新失敗" })); } }
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); }
public ActionResult CartSummary() { ViewData["CartCount"] = CartItems.Sum(o => o.Amount); return(PartialView("CartSummary")); }
public int TotalQuantity() { return(CartItems.Sum(x => x.Quantity)); }
public void OnGet() { CartItems = shoppingCart.GetCartItems(); TotalCount = CartItems.Sum(c => c.Count); Total = CartItems.Sum(c => c.Count * c.Product.Price); }