public bool AddBook(BookModel newBook) { try { using (BooksDBEntities db = new BooksDBEntities()) { db.Books.Add( new Book() { Price = newBook.Price, NumOfPages = newBook.NumOfPages, BookName = newBook.BookName, Author = new Author { Age = newBook.Author.Age, Image = newBook.Author.Image, Name = newBook.Author.Name } } ); db.SaveChanges(); return(true); }; } catch (Exception) { return(false); } }
public ActionResult Index() { using (BooksDBEntities db = new BooksDBEntities()) { List <Book> list = db.uspGetBooks().ToList(); return(View(list)); } }
// GET: Books/Details/5 public ActionResult Details(int id) { using (BooksDBEntities db = new BooksDBEntities()) { Book book = db.uspGetBooksById(id).FirstOrDefault(); return(View(book)); } }
public List <AuthorModel> GetAllAuthors() { using (BooksDBEntities db = new BooksDBEntities()) { return(db.Authors.Select(a => new AuthorModel() { Age = a.Age, Image = a.Image, Name = a.Name }).ToList()); } }
public AuthorModel GetAuthor(string name) { using (BooksDBEntities db = new BooksDBEntities()) { return(db.Authors .Where(a => a.Name == name) .Select(a => new AuthorModel() { Age = a.Age, Image = a.Image, Name = a.Name }).FirstOrDefault()); }; }
public bool RemoveBook(string name) { using (BooksDBEntities db = new BooksDBEntities()) { var BookToRemove = db.Books .Where(b => b.BookName == name).FirstOrDefault(); if (BookToRemove != null) { db.Books.Remove(BookToRemove); db.SaveChanges(); return(true); } else { return(false); } }; }
public bool RemoveAuthor(string name) { using (BooksDBEntities db = new BooksDBEntities()) { var AuthorToRemove = db.Authors .Where(a => a.Name == name).FirstOrDefault(); if (AuthorToRemove != null) { db.Authors.Remove(AuthorToRemove); db.SaveChanges(); return(true); } else { return(false); } }; }
public bool EditAuthor(string name, AuthorModel newAuthor) { try { using (BooksDBEntities db = new BooksDBEntities()) { var toEdit = db.Authors .Where(a => a.Name == name).FirstOrDefault(); toEdit.Age = newAuthor.Age; toEdit.Image = newAuthor.Image; db.SaveChanges(); return(true); }; } catch (Exception) { return(false); } }
public bool EditBook(string name, BookModel newBook) { try { using (BooksDBEntities db = new BooksDBEntities()) { var toEdit = db.Books .Where(b => b.BookName == name).FirstOrDefault(); toEdit.NumOfPages = newBook.NumOfPages; toEdit.Price = newBook.Price; db.SaveChanges(); return(true); }; } catch (Exception) { return(false); } }
public List <BookModel> GettAllBooks() { using (BooksDBEntities db = new BooksDBEntities()) { return(db.Books.Select(b => new BookModel() { BookName = b.BookName, NumOfPages = b.NumOfPages, Price = b.Price, Author = new AuthorModel() { Age = b.Author.Age, Image = b.Author.Image, Name = b.Author.Name } } ).ToList()); } }
public BookModel GetBook(string name) { using (BooksDBEntities db = new BooksDBEntities()) { return(db.Books .Where(b => b.BookName == name) .Select(b => new BookModel() { BookName = b.BookName, NumOfPages = b.NumOfPages, Price = b.Price, Author = new AuthorModel() { Age = b.Author.Age, Image = b.Author.Image, Name = b.Author.Name } }).FirstOrDefault()); }; }
public bool AddAuthor(AuthorModel newAuthor) { try { using (BooksDBEntities db = new BooksDBEntities()) { db.Authors.Add( new Author() { Age = newAuthor.Age, Image = newAuthor.Image, Name = newAuthor.Name } ); db.SaveChanges(); return(true); }; } catch (Exception) { return(false); } }