Пример #1
0
        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;
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
 public int CreateOrder(Order order, ShoppingCart cart)
 {
     if (order != null && cart != null)
     {
         return 1;
     }
     else
     {
         return -1;
     }
 }
Пример #4
0
 public bool EmptyCart(ShoppingCart cart)
 {
     if(cart != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #5
0
 public bool AddToCart(Product product, ShoppingCart cart)
 {
     if(product != null && cart != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #6
0
 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;
     }
 }
Пример #7
0
        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;
        }
Пример #8
0
 public int GetCount(ShoppingCart cart)
 {
     if(cart != null)
     {
         return 1;
     }
     else
     {
         return -1;
     }
 }
Пример #9
0
        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;
            }
        }
Пример #10
0
 public decimal GetTotal(ShoppingCart cart)
 {
     return temp.GetTotal(cart);
 }
Пример #11
0
 public bool MigrateCart(string userName, ShoppingCart cart)
 {
     return temp.MigrateCart(userName, cart);
 }
Пример #12
0
 public int CreateOrder(Order order, ShoppingCart cart)
 {
     return temp.CreateOrder(order, cart);
 }
Пример #13
0
 public List<Cart> GetCartItems(ShoppingCart cart)
 {
     return temp.GetCartItems(cart);
 }
Пример #14
0
        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;
            }
        }
Пример #15
0
 public decimal GetTotal(ShoppingCart cart)
 {
     if (cart != null)
     {
         return 1;
     }
     else
     {
         return -1;
     }
 }
Пример #16
0
 public decimal getTotalBefore(Order order, ShoppingCart cart)
 {
     if (order != null && cart != null)
     {
         return 1;
     }
     else
     {
         return -1;
     }
 }
Пример #17
0
 public bool MigrateCart(string userName, ShoppingCart cart)
 {
     if(!userName.Equals(String.Empty) && cart != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #18
0
 public int RemoveFromCart(int id, ShoppingCart cart)
 {
     if(id != 0 && cart != null)
     {
         return 1;
     }
     else
     {
         return -1;
     }
 }
Пример #19
0
 public ShoppingCart GetCart(Controller controller)
 {
     if(controller != null)
     {
         return GetCart(controller.HttpContext);
     }
     else
     {
         var cart = new ShoppingCart()
         {
             ShopCartId = null
         };
         return cart;
     }
 }
Пример #20
0
 public ShoppingCart GetCart(HttpContextBase context)
 {
     var temp = new ShoppingCartDAL();
     var cart = new ShoppingCart()
     {
         ShopCartId = temp.GetCartId(context)
     };
     return cart;
 }
Пример #21
0
 public bool AddToCart(Product product, ShoppingCart cart)
 {
     return temp.AddToCart(product, cart);
 }
Пример #22
0
 public List<Cart> GetCartItems(ShoppingCart cart)
 {
     return storeDB.Carts.Where(
         c => c.CartId == cart.ShopCartId).ToList();
 }
Пример #23
0
 public bool EmptyCart(ShoppingCart cart)
 {
     return temp.EmptyCart(cart);
 }
Пример #24
0
        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;
        }
Пример #25
0
 public int GetCount(ShoppingCart cart)
 {
     return temp.GetCount(cart);
 }
Пример #26
0
        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;
        }
Пример #27
0
 public decimal getTotalBefore(Order order, ShoppingCart cart)
 {
     return temp.getTotalBefore(order, cart);
 }
Пример #28
0
        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;
        }
Пример #29
0
 public int RemoveFromCart(int id, ShoppingCart cart)
 {
     return temp.RemoveFromCart(id, cart);
 }
Пример #30
0
 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;
     }
 }