public static List <Book> GetAllBooks()
 {
     using (var db = new SE407_BookstoreContext())
     {
         return(db.Books.ToList());
     }
 }
 public static List <Book> GetAllAuthorBooks(String author)
 {
     using (var db = new SE407_BookstoreContext())
     {
         return(db.Books
                .Join(db.Authors,
                      b => b.AuthorId,
                      a => a.AuthorId,
                      (b, a) => new
         {
             BookId = b.BookId,
             BookTitle = b.BookTitle,
             GenreId = b.GenreId,
             AuthorId = b.AuthorId,
             YearOfRelease = b.YearOfRelease,
             AuthorLast = a.AuthorLast
         }).Where(w => w.AuthorLast == author)
                .Select(b => new Book
         {
             BookId = b.BookId,
             BookTitle = b.BookTitle,
             GenreId = b.GenreId,
             AuthorId = b.AuthorId,
             YearOfRelease = b.YearOfRelease
         }).ToList());
     }
 }
 public static Book GetBookByTitle(String titleStr)
 {
     using (var db = new SE407_BookstoreContext())
     {
         return(db.Books.Where(b => b.BookTitle == titleStr).FirstOrDefault());
     }
 }
Beispiel #4
0
 public static List <Genre> GetAllGenres()
 {
     using (var db = new SE407_BookstoreContext())
     {
         return(db.Genres.ToList());
     }
 }
Beispiel #5
0
 public static List <Author> GetAllAuthors()
 {
     using (var db = new SE407_BookstoreContext())
     {
         return(db.Authors.ToList());
     }
 }
Beispiel #6
0
        public static List <Book> GetAllBooksFull()
        {
            using (var db = new SE407_BookstoreContext())
            {
                var books = db.Books
                            .Include(books => books.Author)
                            .Include(books => books.Genre)
                            .ToList();

                return(books);
            }
        }
Beispiel #7
0
 public static Book GetFullBookById(int id)
 {
     using (var db = new SE407_BookstoreContext())
     {
         var book = db.Books
                    .Include(b => b.Author)
                    .Include(b => b.Genre)
                    .Where(b => b.BookId == id)
                    .FirstOrDefault();
         return(book);
     }
 }
Beispiel #8
0
 public static void addBook(Book book)
 {
     try
     {
         using (var db = new SE407_BookstoreContext())
         {
             db.Books.Add(book);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
Beispiel #9
0
 public static void deleteBook(int id)
 {
     try
     {
         using (var db = new SE407_BookstoreContext())
         {
             var bookToDelete = db.Books.Find(id);
             db.Books.Remove(bookToDelete);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }