예제 #1
0
        public void GetAllBooks1()
        {
            var books = new Database("product").ExecuteReader("select * from Book", null, dr => {
                var book = new Book {Id = (int) dr["Id"], Name = (string) dr["Name"]};
                return book;
            });

            foreach (var book in books)
                Console.WriteLine(book.Name);
        }
예제 #2
0
파일: Program.cs 프로젝트: thedoomx/CSharp
        private static Book AddBook(string title, string description, DateTime datePublished, int pages, string isbn, int bookCopies)
        {
            using (BookDBDataContext context = new BookDBDataContext())
            {
                Book newBook = new Book()
                {
                    Title = title,
                    BookResume = description,
                    DatePublished = datePublished,
                    Pages = pages,
                    ISBN = isbn
                };

                context.Books.InsertOnSubmit(newBook);

                while (bookCopies > 0)
                {
                    var bookCopy = new BookCopy()
                    {
                        Book = newBook
                    };
                    context.BookCopies.InsertOnSubmit(bookCopy);
                    bookCopies--;
                }

                //var existing = context.Authors.FirstOrDefault(a => a.FirstName.Contains("G"));

                //if (existing != null)
                //{
                //    var bookAuthor = new BookAuthor()
                //    {
                //        BookID = newBook.ID,
                //        AuthorID = existing.ID
                //    };
                //}

                //var bookGenre = new BookGenre()
                //{
                //    BookID = newBook.ID
                //};

                context.SubmitChanges();
                return newBook;
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: thedoomx/CSharp
        public static void LoanBookToUser(User user, Book book)
        {
            using (var context = new BookDBDataContext())
            {
                bool alreadyLoaned = (from bu in context.BookUsers
                                  where bu.UserID == user.ID
                                    && bu.BookCopy.Book.ID == book.ID
                                    && bu.ReturnDate >= DateTime.Now.Date
                                  select 1).Count() > 0;

                if (alreadyLoaned == true)
                {
                    throw new ArgumentException("You have already loaned this book!");
                }

                BookCopy availableCopy = (from bu in context.BookUsers
                                          where bu.BookCopy.BookID == book.ID
                                          && bu.ReturnDate == null
                                          select bu.BookCopy).FirstOrDefault();

                var avail = (from bc in context.BookCopies
                             where bc.BookID == book.ID
                                 && bc.BookUsers.Count() == 0
                             select bc).FirstOrDefault();

                if (availableCopy == null)
                {
                    throw new ArgumentException("There is no available copy of this book!");
                }

            }
        }
예제 #4
0
 partial void DeleteBook(Book instance);
예제 #5
0
 partial void UpdateBook(Book instance);
예제 #6
0
 partial void InsertBook(Book instance);