public List <Product> findAll() { using (MyProductEntities mde = new MyProductEntities()) { return(mde.ProductEntities.Select(pe => new Product { Id = pe.id, Name = pe.Name, Price = pe.Price.Value, Quantity = pe.Quantity.Value }).ToList()); } }
public Product find(int id) { using (MyProductEntities mde = new MyProductEntities()) { int did = Convert.ToInt32(id); return(mde.ProductEntities.Where(pe => pe.id == id).Select(pe => new Product { Id = pe.id, Name = pe.Name, Price = pe.Price.Value, Quantity = pe.Quantity.Value }).FirstOrDefault()); } }
public bool delete(Product product) { using (MyProductEntities mde = new MyProductEntities()) { try { int id = Convert.ToInt32(product.Id); ProductEntity pe = mde.ProductEntities.Single(p => p.id == id); mde.ProductEntities.Remove(pe); mde.SaveChanges(); return(true); } catch { return(false); } } }
public bool edit(Product product) { using (MyProductEntities mde = new MyProductEntities()) { try { int id = Convert.ToInt32(product.Id); ProductEntity pe = mde.ProductEntities.Single(p => p.id == id); pe.Name = product.Name; pe.Price = product.Price; pe.Quantity = product.Quantity; mde.SaveChanges(); return(true); } catch { return(false); } } }
public bool create(Product product) { using (MyProductEntities mde = new MyProductEntities()) { try { ProductEntity pe = new ProductEntity(); pe.Name = product.Name; pe.Price = product.Price; pe.Quantity = product.Quantity; mde.ProductEntities.Add(pe); mde.SaveChanges(); return(true); } catch { return(false); } } }