Ejemplo n.º 1
0
 public List<Cart> GetOrdersInCart(string clientId)
 {
     G2Entities db = new G2Entities();
     List<Cart> orders = (from x in db.Carts
                          where x.ClientID == clientId
                          && x.IsInChart
                          orderby x.DatePurchased descending
                          select x).ToList();
     return orders;
 }
Ejemplo n.º 2
0
        public string InsertProduct(Product product)
        {
            try
            {
                G2Entities db = new G2Entities();
                db.Products.Add(product);
                db.SaveChanges();

                return product.Name + " was succesfully inserted";
            }
            catch (Exception e)
            {
                return "Error:" + e;
            }
        }
Ejemplo n.º 3
0
 public string InsertCart(Cart cart)
 {
     try
     {
         G2Entities db = new G2Entities();
         db.Carts.Add(cart);
         db.SaveChanges();
         
         return "Order was succesfully inserted";
     }
     catch (Exception e)
     {
         return "Error:" + e;
     }
 }
Ejemplo n.º 4
0
 public Product GetProduct(int id)
 {
     try
     {
         using (G2Entities db = new G2Entities())
         {
             Product product = db.Products.Find(id);
             return product;
         }
     }
     catch (Exception)
     {
         return null;
     }
 }
Ejemplo n.º 5
0
    public int GetAmountOfOrders(string clientId)
    {
        try
        {
            G2Entities db = new G2Entities();
            int amount = (from x in db.Carts
                          where x.ClientID == clientId
                          && x.IsInChart
                          select x.Amount).Sum();

            return amount;
        }
        catch
        {
            return 0;
        }
    }
Ejemplo n.º 6
0
    public string DeleteCart(int id)
    {
        try
        {
            G2Entities db = new G2Entities();
            Cart cart = db.Carts.Find(id);

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

            return cart.DatePurchased + "was succesfully deleted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
Ejemplo n.º 7
0
        public string DeleteProduct(int id)
        {
            try
            {
                G2Entities db = new G2Entities();
                Product product = db.Products.Find(id);

                db.Products.Attach(product);
                db.Products.Remove(product);
                db.SaveChanges();

                return product.Name + " was succesfully deleted";
            }
            catch (Exception e)
            {
                return "Error:" + e;
            }
        }
Ejemplo n.º 8
0
    public string UpdateProductType(int id, ProductType productType)
    {
        try
        {
            G2Entities db = new G2Entities();

            //Fetch object from db
            ProductType p = db.ProductTypes.Find(id);

            p.Name = productType.Name;

            db.SaveChanges();
            return productType.Name + "was succesfully updated";

        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
Ejemplo n.º 9
0
        public string UpdateProduct(int id, Product product)
        {
            try
            {
                G2Entities db = new G2Entities();                
                Product p = db.Products.Find(id);
                
                p.Name = product.Name;
                p.Price = product.Price;
                p.TypeId = product.TypeId;
                p.Description = product.Description;
                p.Image = product.Image;

                db.SaveChanges();
                return product.Name + " was succesfully updated";

            }
            catch (Exception e)
            {
                return "Error:" + e;
            }
        }
Ejemplo n.º 10
0
    public string UpdateCart(int id, Cart cart)
    {
        try
        {
            G2Entities db = new G2Entities();

            //Fetch object from db
            Cart p = db.Carts.Find(id);

            p.DatePurchased = cart.DatePurchased;
            p.ClientID = cart.ClientID;
            p.Amount = cart.Amount;
            p.IsInChart = cart.IsInChart;
            p.ProductID = cart.ProductID;

            db.SaveChanges();
            return cart.DatePurchased + " was succesfully updated";

        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
Ejemplo n.º 11
0
    public void UpdateQuantity(int id, int quantity)
    {
        G2Entities db = new G2Entities();
        Cart p = db.Carts.Find(id);
        p.Amount = quantity;

        db.SaveChanges();
    }
Ejemplo n.º 12
0
        public List<Product> GetProductsByRank()
        {
            try
            {
                using (G2Entities db = new G2Entities())
                {
                    List<Product> products = (from x in db.Products
                        orderby x.Rank descending
                                              select x).Take(4).ToList();
                    return products;
                }
            }
            catch (Exception)
            {

                return null;
            }
        }
Ejemplo n.º 13
0
        public List<Product> ListNewProducts()
        {
            G2Entities db = new G2Entities();

           List<Product> products = (from x in db.Products orderby x.ProductDate descending select x).Take(4).ToList();
            return products;

        }
Ejemplo n.º 14
0
        public string GetIdFromName(string ProductName)
        {
            G2Entities db = new G2Entities();

            string productName = (from x in db.Products where x.Name == ProductName select x.Id).ToString();
            return productName;
        }
Ejemplo n.º 15
0
        public List<string> SearchProduct(string name)
        {
            G2Entities product = new G2Entities();

            return
                product.Products.Where(x => x.Name.StartsWith(name, StringComparison.OrdinalIgnoreCase))
                    .Select(x => x.Name)
                    .ToList();
        } 
Ejemplo n.º 16
0
    public void MarkOrdersAsPaid(List<Cart> carts)
    {
        G2Entities db = new G2Entities();

        if (carts != null)
        {
            foreach (Cart cart in carts)
            {
                Cart oldCart = db.Carts.Find(cart.ID);
                oldCart.DatePurchased = DateTime.Now;
                oldCart.IsInChart = false;
            }
            db.SaveChanges();
        }
    }
Ejemplo n.º 17
0
 public List<Product> GetAllProducts()
 {
     try
     {
         using (G2Entities db = new G2Entities())
         {
             List<Product> products = (from x in db.Products
                 select x).ToList();
             return products;
         }
     }
     catch (Exception)
     {
         return null;
     }
 }
Ejemplo n.º 18
0
 public List<Product> GetProductsByType(int typeId)
 {
     try
     {
         using (G2Entities db = new G2Entities())
         {
             List<Product> products = (from x in db.Products
                                       where x.TypeId == typeId
                                       select x).ToList();
             return products;
         }
     }
     catch (Exception)
     {
         return null;
     }
 }