Exemplo n.º 1
0
        public void UpdateQuantity(int id, int quantity)
        {
            ShopdbEntities3 db   = new ShopdbEntities3();
            Cart            cart = db.Carts.Find(id);

            cart.Quantity = quantity;

            db.SaveChanges();
        }
Exemplo n.º 2
0
        public List <Cart> GetOrdersInCart(string userId)
        {
            ShopdbEntities3 db     = new ShopdbEntities3();
            List <Cart>     orders = (from x in db.Carts
                                      where (x.Customer_ID).ToString() == userId &&
                                      x.IsInCart
                                      orderby x.Order_Date
                                      select x).ToList();

            return(orders);
        }
Exemplo n.º 3
0
        public string InsertProductType(Product_Type productType)
        {
            try
            {
                ShopdbEntities3 db = new ShopdbEntities3();
                db.Product_Type.Add(productType);
                db.SaveChanges();

                return(productType.Type + " was succesfully inserted");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }
Exemplo n.º 4
0
 public List <Product> GetAllProductsByType(int typeId)
 {
     try
     {
         using (ShopdbEntities3 db = new ShopdbEntities3())
         {
             List <Product> products = (from x in db.Products where x.Product_Type_ID == typeId select x).ToList();
             return(products);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 5
0
 public List <Product> GetAllProducts()
 {
     try
     {
         using (ShopdbEntities3 db = new ShopdbEntities3())
         {
             List <Product> products = (from x in db.Products select x).ToList();
             return(products);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 6
0
 public Product GetProduct(int id)
 {
     try
     {
         using (ShopdbEntities3 db = new ShopdbEntities3())
         {
             Product product = db.Products.Find(id);
             return(product);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 7
0
        public void MarkOrderAsPaid(List <Cart> carts)
        {
            ShopdbEntities3 db = new ShopdbEntities3();

            if (carts != null)
            {
                foreach (Cart cart in carts)
                {
                    Cart oldCart = db.Carts.Find(cart.Cart_ID);
                    oldCart.Order_Date = DateTime.Now;
                    oldCart.IsInCart   = false;
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 8
0
        public string InsertCart(Cart cart)
        {
            try
            {
                ShopdbEntities3 db = new ShopdbEntities3();
                db.Carts.Add(cart);
                db.SaveChanges();

                return(cart.Order_Date + " order was succesfully added");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }
Exemplo n.º 9
0
 public int GetAmountOfOrders(string userId)
 {
     try
     {
         ShopdbEntities3 db     = new ShopdbEntities3();
         int             amount = (int)(from x in db.Carts
                                        where (x.Customer_ID).ToString() == userId &&
                                        x.IsInCart
                                        select x.Quantity).Sum();
         return(amount);
     }
     catch
     {
         return(0);
     }
 }
Exemplo n.º 10
0
        public string DeleteProductType(int id)
        {
            try
            {
                ShopdbEntities3 db          = new ShopdbEntities3();
                Product_Type    productType = db.Product_Type.Find(id);

                db.Product_Type.Attach(productType);
                db.Product_Type.Remove(productType);
                db.SaveChanges();

                return(productType.Type + " was succesfully deleted");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }
Exemplo n.º 11
0
        public string UpdateProductType(int id, Product_Type productType)
        {
            try
            {
                ShopdbEntities3 db = new ShopdbEntities3();
                Product_Type    p  = db.Product_Type.Find(id);

                p.Type = productType.Type;


                db.SaveChanges();
                return(productType.Type + " was succesfully updated");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }
Exemplo n.º 12
0
        public string DeleteCart(int id)
        {
            try
            {
                ShopdbEntities3 db   = new ShopdbEntities3();
                Cart            cart = db.Carts.Find(id);

                db.Carts.Attach(cart);
                db.Carts.Remove(cart);
                db.SaveChanges();

                return(cart.Order_Date + " was succesfully deleted");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }
Exemplo n.º 13
0
        public string UpdateCart(int id, Cart cart)
        {
            try
            {
                ShopdbEntities3 db = new ShopdbEntities3();
                Cart            p  = db.Carts.Find(id);

                p.Order_Date  = cart.Order_Date;
                p.Customer_ID = cart.Customer_ID;
                p.IsInCart    = cart.IsInCart;
                p.Product_ID  = cart.Product_ID;
                db.SaveChanges();
                return(cart.Order_Date + " was succesfully updated");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }
Exemplo n.º 14
0
        public string UpdateProduct(int id, Product product)
        {
            try
            {
                ShopdbEntities3 db = new ShopdbEntities3();
                Product         p  = db.Products.Find(id);

                p.Name            = product.Name;
                p.Price           = product.Price;
                p.Product_Type_ID = product.Product_Type_ID;
                p.Description     = product.Description;
                p.Image           = product.Image;

                db.SaveChanges();
                return(product.Name + " was succesfully updated");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }