public bool AddToCart(Product product, ShoppingCart cart) { if(product != null && cart != null) { var cartItem = storeDB.Carts.SingleOrDefault( c => c.CartId == cart.ShopCartId && c.ProductId == product.ProductId); if (cartItem == null) { cartItem = new Cart { ProductId = product.ProductId, CartId = cart.ShopCartId, Count = 1, DateCreated = DateTime.Now }; storeDB.Carts.Add(cartItem); } else { cartItem.Count++; } storeDB.SaveChanges(); return true; } else { return false; } }
public int CreateOrder(Order order, ShoppingCart cart) { decimal orderTotal = 0; var cartItems = GetCartItems(cart); foreach (var item in cartItems) { var orderDetail = new OrderDetail { ProductId = item.ProductId, OrderId = order.OrderId, ProductPrice = item.Product.Price, Quantity = item.Count }; orderTotal += (item.Count * item.Product.Price); storeDB.OrderDetails.Add(orderDetail); } order.Total = orderTotal; order.OrderDetails = storeDB.OrderDetails.Where(o => o.OrderId == order.OrderId).ToList(); storeDB.SaveChanges(); EmptyCart(cart); return order.OrderId; }
public int CreateOrder(Order order, ShoppingCart cart) { if (order != null && cart != null) { return 1; } else { return -1; } }
public bool EmptyCart(ShoppingCart cart) { if(cart != null) { return true; } else { return false; } }
public bool AddToCart(Product product, ShoppingCart cart) { if(product != null && cart != null) { return true; } else { return false; } }
public ShoppingCart GetCart(HttpContextBase context) { if(context != null) { var temp = new ShoppingCartStub(); var cart = new ShoppingCart() { ShopCartId = temp.GetCartId(context) }; return cart; } else { var cart = new ShoppingCart() { ShopCartId = null }; return cart; } }
public int RemoveFromCart(int id, ShoppingCart cart) { var cartItem = storeDB.Carts.Single( c => c.CartId == cart.ShopCartId && c.RecordId == id); int itemCount = 0; if (cartItem != null) { if (cartItem.Count > 1) { cartItem.Count--; itemCount = cartItem.Count; } else { storeDB.Carts.Remove(cartItem); } storeDB.SaveChanges(); } return itemCount; }
public int GetCount(ShoppingCart cart) { if(cart != null) { return 1; } else { return -1; } }
public bool MigrateCart(string userName, ShoppingCart cart) { if(!userName.Equals(String.Empty) && cart != null) { var shoppingCart = storeDB.Carts.Where( c => c.CartId == cart.ShopCartId); foreach (Cart item in shoppingCart) { item.CartId = userName; } storeDB.SaveChanges(); return true; } else { return false; } }
public decimal GetTotal(ShoppingCart cart) { return temp.GetTotal(cart); }
public bool MigrateCart(string userName, ShoppingCart cart) { return temp.MigrateCart(userName, cart); }
public int CreateOrder(Order order, ShoppingCart cart) { return temp.CreateOrder(order, cart); }
public List<Cart> GetCartItems(ShoppingCart cart) { return temp.GetCartItems(cart); }
public bool EmptyCart(ShoppingCart cart) { if(cart != null) { var cartItems = storeDB.Carts.Where( c => c.CartId == cart.ShopCartId); foreach (var cartItem in cartItems) { storeDB.Carts.Remove(cartItem); } storeDB.SaveChanges(); return true; } else { return false; } }
public decimal GetTotal(ShoppingCart cart) { if (cart != null) { return 1; } else { return -1; } }
public decimal getTotalBefore(Order order, ShoppingCart cart) { if (order != null && cart != null) { return 1; } else { return -1; } }
public bool MigrateCart(string userName, ShoppingCart cart) { if(!userName.Equals(String.Empty) && cart != null) { return true; } else { return false; } }
public int RemoveFromCart(int id, ShoppingCart cart) { if(id != 0 && cart != null) { return 1; } else { return -1; } }
public ShoppingCart GetCart(Controller controller) { if(controller != null) { return GetCart(controller.HttpContext); } else { var cart = new ShoppingCart() { ShopCartId = null }; return cart; } }
public ShoppingCart GetCart(HttpContextBase context) { var temp = new ShoppingCartDAL(); var cart = new ShoppingCart() { ShopCartId = temp.GetCartId(context) }; return cart; }
public bool AddToCart(Product product, ShoppingCart cart) { return temp.AddToCart(product, cart); }
public List<Cart> GetCartItems(ShoppingCart cart) { return storeDB.Carts.Where( c => c.CartId == cart.ShopCartId).ToList(); }
public bool EmptyCart(ShoppingCart cart) { return temp.EmptyCart(cart); }
public int GetCount(ShoppingCart cart) { int? count = (from cartItems in storeDB.Carts where cartItems.CartId == cart.ShopCartId select (int?)cartItems.Count).Sum(); return count ?? 0; }
public int GetCount(ShoppingCart cart) { return temp.GetCount(cart); }
public decimal GetTotal(ShoppingCart cart) { decimal? total = (from cartItems in storeDB.Carts where cartItems.CartId == cart.ShopCartId select (int?)cartItems.Count * cartItems.Product.Price).Sum(); return total ?? decimal.Zero; }
public decimal getTotalBefore(Order order, ShoppingCart cart) { return temp.getTotalBefore(order, cart); }
public decimal getTotalBefore(Order order, ShoppingCart cart) { decimal orderTotal = 0; var cartItems = GetCartItems(cart); foreach (var item in cartItems) { orderTotal += (item.Count * item.Product.Price); } return orderTotal; }
public int RemoveFromCart(int id, ShoppingCart cart) { return temp.RemoveFromCart(id, cart); }
public List<Cart> GetCartItems(ShoppingCart cart) { if(cart != null) { var list = new List<Cart>(); var ca = new Cart() { CartId = "1", Count = 1, DateCreated = DateTime.Now, RecordId = 1 }; list.Add(ca); return list; } else { return null; } }