Example #1
0
 public static List <Book> GetAllBooks()
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Books.ToList());
     }
 }
Example #2
0
 public static List <Book> GetMoviesByAuthorLastName(String author)
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Books
                .Join(db.Authors,
                      m => m.Author.AuthorId,
                      t => t.AuthorId,
                      (m, t) => new
         {
             BookId = m.BookId,
             BookTitle = m.BookTitle,
             YearOfRelease = m.YearOfRelease,
             GenreId = m.GenreId,
             AuhtorId = m.AuthorId,
             AuhtorLast = m.Author.AuthorLast,
         }).Where(w => w.AuhtorLast == author)
                .Select(m => new Book
         {
             BookId = m.BookId,
             BookTitle = m.BookTitle,
             YearOfRelease = m.YearOfRelease,
             GenreId = m.GenreId,
             AuthorId = m.AuhtorId
         }).ToList());
     }
 }
Example #3
0
 public static List <Author> GetAllAuthors()
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Authors.ToList());
     }
 }
Example #4
0
 public static List <Book> GetBookByTitle(string title)
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Books
                .Join(db.Authors,
                      m => m.Author.AuthorId,
                      t => t.AuthorId,
                      (m, t) => new
         {
             BookId = m.BookId,
             Title = m.BookTitle,
             ReleaseYear = m.YearOfRelease,
             GenreId = m.GenreId,
             AuthorId = m.AuthorId,
         }).Where(w => w.Title == title)
                .Select(m => new Book
         {
             BookId = m.BookId,
             BookTitle = m.Title,
             YearOfRelease = m.ReleaseYear,
             GenreId = m.GenreId,
             AuthorId = m.AuthorId
         }).ToList());
     }
 }
Example #5
0
 public static Book GetBookById(int id)
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Books.Find(id));
     }
 }
Example #6
0
 public static List <Genre> GetAllGenres()
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Genres.ToList());
     }
 }
Example #7
0
 public static List <Book> GetBookBytitle(string title)
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Books.Where(x => x.BookTitle == title).ToList());
     }
 }
 public static void EditBook(Book book)
 {
     try
     {
         using (var db = new SE407_BookStoreContext())
         {
             db.Books.Update(book);
             db.SaveChanges();
         }
     }catch (Exception e) { }
 }
Example #9
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);
            }
        }
Example #10
0
 public static Book GetFullBookById(int id)
 {
     using (var db = new SE407_BookStoreContext())
     {
         var book = db.Books
                    .Include(a => a.Author)
                    .Include(g => g.Genre)
                    .Where(b => b.BookId == id)
                    .FirstOrDefault();
         return(book);
     }
 }
 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)
     {
     }
 }
Example #12
0
 public static List <Book> GetAllBooksByAuthorLast(string lastname)
 {
     using (var db = new SE407_BookStoreContext())
     {
         return(db.Books
                .Join(db.Authors,
                      m => m.AuthorId,
                      t => t.AuthorId,
                      (m, t) => new { M = m, T = t })
                .Where(w => w.T.AuthorLast == lastname)
                .Select(m => new Book
         {
             BookId = m.M.BookId,
             BookTitle = m.M.BookTitle,
             GenreId = m.M.GenreId,
             AuthorId = m.M.GenreId,
             YearOfRelease = m.M.YearOfRelease
         }).ToList());
     }
 }