public static bool RemoveFromCart(int?orderItemID) { CheckPendingOrders(); bool result = false; if (orderItemID.HasValue && Common.Session.CurrentOrderID.HasValue) { ETC.OrderItem item = ETC.OrderItem.ExecuteCreate(orderItemID.Value); item.Delete(); UpdateTotalAmountInOrder(Common.Session.CurrentOrderID.Value); result = true; } return(result); }
private static ETC.OrderItem CheckPendingOrderItems(int ProductID) { ETC.OrderItem result = null; if (Common.Session.CurrentOrderID.HasValue) { List <ETC.OrderItem> list = ETC.OrderItem.ListByOrderID(Common.Session.CurrentOrderID.Value); foreach (ETC.OrderItem item in list) { if (item.ProductID == ProductID) { result = item; break; } } } return(result); }
public static bool AddToCart(int?productID, int quantity) { bool result = false; if (productID.HasValue) { CheckPendingOrders(); ShopViewModel model = new ShopViewModel(productID.Value); ETC.OrderItem orderItem = CheckPendingOrderItems(model.ID); if (orderItem != null) { int newQuantity = orderItem.Quantity + quantity; orderItem.Update(newQuantity, model.Price, (model.Price * newQuantity)); UpdateTotalAmountInOrder(Common.Session.CurrentOrderID ?? default(int)); result = true; } else { orderItem = ETC.OrderItem.ExecuteCreate( Common.Session.CurrentOrderID ?? default(int), model.ID, quantity, model.Price, (model.Price * quantity)); orderItem.Insert(); UpdateTotalAmountInOrder(Common.Session.CurrentOrderID ?? default(int)); result = true; } } return(result); }