public string InsertCart(Cart cart)
 {
     try
     {
         GarageDBEntities1 db = new GarageDBEntities1();
         db.Carts.Add(cart);
         db.SaveChanges();
         return(cart.DatePurchased + "was successfully inserted");
     }
     catch (Exception e)
     {
         return("Error:" + e);
     }
 }
 public string InsertProduct(Product product)
 {
     try
     {
         GarageDBEntities1 db = new GarageDBEntities1();
         db.Products.Add(product);
         db.SaveChanges();
         return(product.Name + "was successfully inserted");
     }
     catch (Exception e)
     {
         return("Error:" + e);
     }
 }
 public string DeleteCart(int id)
 {
     try
     {
         GarageDBEntities1 db = new GarageDBEntities1();
         Cart cart            = db.Carts.Find(id);
         db.Carts.Attach(cart);
         db.Carts.Remove(cart);
         db.SaveChanges();
         return(cart.DatePurchased + "was successfully deleted!!");
     }
     catch (Exception e)
     {
         return("Error:" + e);
     }
 }
 public string DeleteProduct(int id)
 {
     try
     {
         GarageDBEntities1 db      = new GarageDBEntities1();
         Product           product = db.Products.Find(id);
         db.Products.Attach(product);
         db.Products.Remove(product);
         db.SaveChanges();
         return(product.Name + "was successfully deleted!!");
     }
     catch (Exception e)
     {
         return("Error:" + e);
     }
 }
Example #5
0
    public string UpdateProductType(int id, ProductType productType)
    {
        try
        {
            GarageDBEntities1 db = new GarageDBEntities1();
            //Fetch object from db
            ProductType p = db.ProductTypes.Find(id);
            p.Name = productType.Name;

            db.SaveChanges();
            return(productType.Name + "was successfully updated");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
 public string UpdateCart(int id, Cart cart)
 {
     try
     {
         GarageDBEntities1 db = new GarageDBEntities1();
         //Fetch object from db
         Cart p = db.Carts.Find(id);
         p.DatePurchased = cart.DatePurchased;
         p.ClientID      = cart.ClientID;
         p.Amount        = cart.Amount;
         p.IsInCart      = cart.IsInCart;
         p.ProductID     = cart.ProductID;
         db.SaveChanges();
         return(cart.DatePurchased + "was successfully updated");
     }
     catch (Exception e)
     {
         return("Error:" + e);
     }
 }
 public string UpdateProduct(int id, Product product)
 {
     try
     {
         GarageDBEntities1 db = new GarageDBEntities1();
         //Fetch object from db
         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 successfully updated");
     }
     catch (Exception e)
     {
         return("Error:" + e);
     }
 }