public List <Product> findAll() { using (hackEntities mybook = new hackEntities()) { return(mybook.bookEntities.Select(be => new Product { bookID = be.bookID, title = be.title, author = be.author, price = be.price.Value, quantity = be.quantity.Value }).ToList()); }; }
public Product find(string book_ID) { using (hackEntities mybook = new hackEntities()) { int bookid = Convert.ToInt32(book_ID); return(mybook.bookEntities.Where(be => be.bookID == bookid).Select(be => new Product { bookID = be.bookID, title = be.title, author = be.author, price = be.price.Value, quantity = be.quantity.Value //creationDate = be.creationDate }).First()); }; }
public bool delete(Product product) { using (hackEntities mybook = new hackEntities()) { try { int bookid = Convert.ToInt32(product.bookID); bookEntity be = mybook.bookEntities.Single(p => p.bookID == bookid); mybook.bookEntities.Remove(be); mybook.SaveChanges(); return(true); } catch { return(false); } }; }
public bool edit(Product product) { using (hackEntities mybook = new hackEntities()) { try { int bookid = Convert.ToInt32(product.bookID); bookEntity be = mybook.bookEntities.Single(p => p.bookID == bookid); be.title = product.title; be.author = product.author; be.price = product.price; be.quantity = product.quantity; mybook.SaveChanges(); return(true); } catch { return(false); } }; }
public bool create(Product product) { using (hackEntities mybook = new hackEntities()) { try { bookEntity be = new bookEntity(); be.title = product.title; be.author = product.author; be.price = product.price; be.quantity = product.quantity; mybook.bookEntities.Add(be); mybook.SaveChanges(); return(true); } catch { return(false); } }; }