コード例 #1
0
ファイル: GenreDAO.cs プロジェクト: dannnoon/Bookcase
 public static Genre GetGenreById(int id)
 {
     using (var db = new BookcaseDB())
     {
         return((from b in db.Genres where b.GenreId == id select b).First());
     }
 }
コード例 #2
0
ファイル: GenreDAO.cs プロジェクト: dannnoon/Bookcase
 public static void AddGenre(Genre genre)
 {
     using (var db = new BookcaseDB())
     {
         db.Genres.Add(genre);
         db.SaveChanges();
     }
 }
コード例 #3
0
ファイル: GenreDAO.cs プロジェクト: dannnoon/Bookcase
 public static Genre[] GetAllGenres()
 {
     using (var db = new BookcaseDB())
     {
         var genres = from b in db.Genres select b;
         return(genres.ToArray());
     }
 }
コード例 #4
0
        public static Book GetBookById(int id)
        {
            using (var db = new BookcaseDB())
            {
                var book = (from b in db.Books where b.BookId == id select b).First();
                book.Genre = GetGenreById(book.GenreId, db);

                return(book);
            }
        }
コード例 #5
0
 public static void DeleteBook(int bookId)
 {
     using (var db = new BookcaseDB())
     {
         db.Entry(new Book()
         {
             BookId = bookId
         }).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #6
0
        public static Book[] GetOwnedBooks()
        {
            using (var db = new BookcaseDB())
            {
                var books = from b in db.Books where b.Filter != FilterType.NOT_OWNED select b;

                foreach (Book book in books)
                {
                    book.Genre = GetGenreById(book.GenreId, db);
                }

                return(books.ToArray());
            }
        }
コード例 #7
0
        public static Book[] GetAllBooks()
        {
            using (var db = new BookcaseDB())
            {
                var books = from b in db.Books select b;

                foreach (Book book in books)
                {
                    book.Genre = GetGenreById(book.GenreId, db);
                }

                return(books.ToArray());
            }
        }
コード例 #8
0
        public static Book[] GetBooksByFilter(FilterType filter)
        {
            using (var db = new BookcaseDB())
            {
                var books = from b in db.Books where b.Filter == filter select b;

                foreach (Book book in books)
                {
                    book.Genre = GetGenreById(book.GenreId, db);
                }

                return(books.ToArray());
            }
        }
コード例 #9
0
        public static void AddBook(Book book)
        {
            using (var db = new BookcaseDB())
            {
                var entity = db.Books.Find(book.BookId);

                if (entity == null)
                {
                    db.Books.Add(book);
                }
                else
                {
                    book.Genre = null;
                    db.Entry(entity).CurrentValues.SetValues(book);
                }

                db.SaveChanges();
            }
        }
コード例 #10
0
 private static Genre GetGenreById(int id, BookcaseDB db)
 {
     return((from g in db.Genres where g.GenreId == id select g).First());
 }