public string InsertPurchase(Purchase purchase) { try { TshirtDBEntities db = new TshirtDBEntities(); db.Purchases.Add(purchase); db.SaveChanges(); return(purchase.Date + " was succesfully added!"); } catch (Exception e) { return("Error " + e); } }
public Product GetProduct(int id) { try { using (TshirtDBEntities db = new TshirtDBEntities()) { Product p = db.Products.Find(id); return(p); } } catch (Exception e) { return(null); } }
public string InsertProduct(Product product) { try { TshirtDBEntities db = new TshirtDBEntities(); db.Products.Add(product); db.SaveChanges(); return(product.Name + " was succesfully added!"); } catch (Exception e) { return("Error " + e); } }
public string InsertSize(Size size) { try { TshirtDBEntities db = new TshirtDBEntities(); db.Sizes.Add(size); db.SaveChanges(); return(size.Name + " was succesfully added!"); } catch (Exception e) { return("Error " + e); } }
public List <Product> GetAllProducts() { try { using (TshirtDBEntities db = new TshirtDBEntities()) { List <Product> products = (from x in db.Products select x).ToList(); return(products); } } catch (Exception e) { return(null); } }
public string DeletePurchase(int id) { try { TshirtDBEntities db = new TshirtDBEntities(); Purchase p = db.Purchases.Find(id); db.Purchases.Attach(p); db.Purchases.Remove(p); db.SaveChanges(); return(p.Date + " was succesfully deleted!"); } catch (Exception e) { return("Error " + e); } }
public List <Product> GetProductsByType(int typeId) { try { using (TshirtDBEntities db = new TshirtDBEntities()) { List <Product> products = (from x in db.Products where x.TypeID == typeId select x).ToList(); return(products); } } catch (Exception e) { return(null); } }
public string UpdateSize(int id, Size size) { try { TshirtDBEntities db = new TshirtDBEntities(); Size p = db.Sizes.Find(id); p.Name = size.Name; db.SaveChanges(); return(size.Name + " was succesfully updated!"); } catch (Exception e) { return("Error " + e); } }
public string UpdatePurchase(int id, Purchase purchase) { try { TshirtDBEntities db = new TshirtDBEntities(); Purchase p = db.Purchases.Find(id); p.Date = purchase.Date; p.Amount = purchase.Amount; p.IsInCart = purchase.IsInCart; p.ProductID = purchase.ProductID; db.SaveChanges(); return(purchase.Date + " was succesfully updated!"); } catch (Exception e) { return("Error " + e); } }
public string UpdateProduct(int id, Product product) { try { TshirtDBEntities db = new TshirtDBEntities(); Product p = db.Products.Find(id); p.Name = product.Name; p.Price = product.Price; p.Image = product.Image; p.Description = product.Description; p.TypeID = product.TypeID; db.SaveChanges(); return(product.Name + " was succesfully updated!"); } catch (Exception e) { return("Error " + e); } }