public string InsertCart(Cart cart) { try { ProteinPowderEntities db = new ProteinPowderEntities(); db.Carts.Add(cart); db.SaveChanges(); return(cart.DatePurchased + "was successfully inserted"); } catch (Exception e) { return("Error:" + e); } }
public Product GetProduct(int id) { try { using (ProteinPowderEntities db = new ProteinPowderEntities()) { Product product = db.Products.Find(id); return(product); } } catch (Exception) { return(null); } }
public string InsertProductType(ProductType productType) { try { ProteinPowderEntities db = new ProteinPowderEntities(); db.ProductTypes.Add(productType); db.SaveChanges(); return(productType.Name + "was successfully inserted"); } catch (Exception e) { return("Error:" + e); } }
public List <Product> GetAllProducts() { try { using (ProteinPowderEntities db = new ProteinPowderEntities()) { List <Product> products = (from x in db.Products select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public List <Product> GetProductsByType(int typeId) { try { using (ProteinPowderEntities db = new ProteinPowderEntities()) { List <Product> products = (from x in db.Products where x.TypeId == typeId select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public string DeleteCart(int id) { try { ProteinPowderEntities db = new ProteinPowderEntities(); 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 DeleteProductType(int id) { try { ProteinPowderEntities db = new ProteinPowderEntities(); ProductType productType = db.ProductTypes.Find(id); db.ProductTypes.Attach(productType); db.ProductTypes.Remove(productType); db.SaveChanges(); return(productType.Name + "was successfully deleted"); } catch (Exception e) { return("Error:" + e); } }
public string UpdateProductType(int id, ProductType productType) { try { ProteinPowderEntities db = new ProteinPowderEntities(); //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 { ProteinPowderEntities db = new ProteinPowderEntities(); //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 { ProteinPowderEntities db = new ProteinPowderEntities(); //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); } }