Example #1
0
        public int?ShoppingRemoveFromCart(int id, string ShoppingCartId)
        {
            using (StoreDbEntities db = new StoreDbEntities())
            {
                // Get the cart
                var cartItem = db.Cart.Single(
                    cart => cart.CartId == ShoppingCartId &&
                    cart.RecordId == id);

                int?itemCount = 0;

                if (cartItem != null)
                {
                    db.Cart.Remove(cartItem);
                    //if (cartItem.Count > 1)
                    //{
                    //    cartItem.Count--;
                    //    itemCount = cartItem.Count;
                    //}
                    //else
                    //{
                    //    db.Cart.Remove(cartItem);
                    //}
                    //// Save changes
                    db.SaveChanges();
                }
                return(itemCount);
            }
        }
Example #2
0
        public void ShoppingAddMoreProductToCart(Produit produit, string ShoppingCartId, int number)
        {
            using (StoreDbEntities db = new StoreDbEntities())
            {
                // Get the matching cart and produit instances
                var cartItem = db.Cart.SingleOrDefault(
                    c => c.CartId == ShoppingCartId &&
                    c.ProduitId == produit.ProduitId);

                if (cartItem == null)
                {
                    // Create a new cart item if no cart item exists
                    cartItem = new Cart
                    {
                        ProduitId   = produit.ProduitId,
                        CartId      = ShoppingCartId,
                        Count       = 1,
                        DateCreated = DateTime.Now
                    };
                    db.Cart.Add(cartItem);
                }
                else
                {
                    // If the item does exist in the cart,
                    // then add one to the quantity
                    cartItem.Count = number;
                }
                // Save changes


                db.SaveChanges();
            }
        }
Example #3
0
 public void ShoppingUpdateStock(OrderDetail order)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = db.Produit.Find(order.ProduitId);
         result.Quantite       -= order.Quantity;
         db.Entry(result).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
        public string Add(Image image)
        {
            if (image == null)
            {
                return(null);
            }

            StoreDbEntities.Images.Add(image);
            StoreDbEntities.SaveChanges();
            return(image.ImagePath);
        }
Example #5
0
 public Marque AddMarque(Marque marque)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = db.Marque.Add(marque);
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
         return(null);
     }
 }
Example #6
0
 public Genre AddGenre(Genre genre)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = db.Genre.Add(genre);
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
         return(null);
     }
 }
Example #7
0
 public Order AddOrder(Order order)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = db.Order.Add(order);
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
         return(null);
     }
 }
Example #8
0
 public OrderDetail AddOrderDetail(OrderDetail orderDetail)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = db.OrderDetail.Add(orderDetail);
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
         return(null);
     }
 }
Example #9
0
 public Produit AddProduit(Produit produit)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = db.Produit.Add(produit);
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
         return(null);
     }
 }
Example #10
0
 public Cart AddCart(Cart cart)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = db.Cart.Add(cart);
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
         return(null);
     }
 }
Example #11
0
 public Produit EditProduit(Produit produit)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = produit;
         db.Entry(result).State = EntityState.Modified;
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
     }
     return(null);
 }
Example #12
0
 public Genre EditGenre(Genre genre)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = genre;
         db.Entry(result).State = EntityState.Modified;
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
     }
     return(null);
 }
Example #13
0
 public OrderDetail EditOrderDetail(OrderDetail orderDetail)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = orderDetail;
         db.Entry(result).State = EntityState.Modified;
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
     }
     return(null);
 }
Example #14
0
 public Cart EditCart(Cart cart)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = cart;
         db.Entry(result).State = EntityState.Modified;
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
     }
     return(null);
 }
Example #15
0
 public Marque EditMarque(Marque marque)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         var result = marque;
         db.Entry(result).State = EntityState.Modified;
         if (db.SaveChanges() > 0)
         {
             return(result);
         }
     }
     return(null);
 }
Example #16
0
        public void ShoppingMigrateCart(string userName, string ShoppingCartId)
        {
            using (StoreDbEntities db = new StoreDbEntities())
            {
                var shoppingCart = db.Cart.Where(
                    c => c.CartId == ShoppingCartId);

                foreach (Cart item in shoppingCart)
                {
                    item.CartId = userName;
                }
                db.SaveChanges();
            }
        }
Example #17
0
 public Produit RemoveProduit(int id)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         if (id != 0)
         {
             var result = db.Produit.Remove(db.Produit.Find(id));
             if (db.SaveChanges() > 0)
             {
                 return(result);
             }
         }
         return(null);
     }
 }
Example #18
0
        public void ShoppingEmptyCart(string ShoppingCartId)
        {
            using (StoreDbEntities db = new StoreDbEntities())
            {
                var cartItems = db.Cart.Where(
                    cart => cart.CartId == ShoppingCartId);

                foreach (var cartItem in cartItems)
                {
                    db.Cart.Remove(cartItem);
                }
                // Save changes
                db.SaveChanges();
            }
        }
Example #19
0
 public Marque RemoveMarque(int id)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         if (id != 0)
         {
             var result = db.Marque.Remove(db.Marque.Find(id));
             if (db.SaveChanges() > 0)
             {
                 return(result);
             }
         }
         return(null);
     }
 }
Example #20
0
        public void Create(Log obj)
        {
            obj.Date = DateTime.Today;
            //UNIX Time = 1300123800000;


            try
            {
                StoreDb.Logs.Add(obj);
                StoreDb.SaveChanges();
            }
            catch (Exception)
            {
            }
        }
Example #21
0
 public OrderDetail RemoveOrderDetail(int id)
 {
     using (StoreDbEntities db = new StoreDbEntities())
     {
         if (id != 0)
         {
             var result = db.OrderDetail.Remove(db.OrderDetail.Find(id));
             if (db.SaveChanges() > 0)
             {
                 return(result);
             }
         }
         return(null);
     }
     throw new NotImplementedException();
 }
Example #22
0
        public int ShoppingCreateOrder(Order order, string myShoppingCartId)
        {
            using (StoreDbEntities db = new StoreDbEntities())
            {
                decimal?orderTotal = 0;

                var cartItems = ShoppingGetCartItems(myShoppingCartId);


                // Iterate over the items in the cart,
                // adding the order details for each
                foreach (var item in cartItems)
                {
                    var orderDetail = new OrderDetail
                    {
                        ProduitId = item.ProduitId,
                        OrderId   = order.OrderId,
                        UnitPrice = item.Produit.Price,
                        Quantity  = item.Count
                    };
                    // Set the order total of the shopping cart
                    orderTotal += (item.Count * item.Produit.Price);

                    db.OrderDetail.Add(orderDetail);
                }
                // Set the order's total to the orderTotal count
                order.Total = orderTotal;

                // Save the order
                db.SaveChanges();
                // Empty the shopping cart
                //EmptyCart();
                // Return the OrderId as the confirmation number
                return(order.OrderId);
            }
        }
Example #23
0
 public void Create(Product product)
 {
     StoreDb.Products.Add(product);
     StoreDb.SaveChanges();
 }
Example #24
0
 public void Create(User user)
 {
     userDb.Users.Add(user);
     userDb.SaveChanges();
 }