public BookRepository GetBookByEdition(string bookID, string Edition) { var context = new LibraryDBContext(); BookRepository book = context.BookRepositories.Include("Book").Where(bookrepo => (bookrepo.BookID == bookID && bookrepo.Edition == Edition)) .Select(bookrepo => bookrepo).SingleOrDefault(); return(book); }
/// <summary> /// To get the book from the database by reading the title of the book /// </summary> /// <param name="title"></param> /// <returns></returns> public Book getBook(string title) { Book book; using (var context = new LibraryDBContext()) { book = context.Books.Include("Authors").Where(bookL => bookL.Title == title).Select(bookL => bookL).FirstOrDefault(); } return(book); }
public IEnumerable <Book> GetBooks(string authorID) { IEnumerable <Book> books; using (var context = new LibraryDBContext()) { books = context.Authors.Include("Books").SelectMany(author => author.Books.Select(book => book)).ToList(); } return(books); }
public Author GetAuthorByName(string name) { Author author; using (var context = new LibraryDBContext()) { author = context.Authors.Include("Books").SingleOrDefault(auth => (auth.firstName + auth.lastName).Contains(name)); } return(author); }
public IEnumerable <Book> GetBYGenre(string genretype) { IEnumerable <Book> books; var context = new LibraryDBContext(); books = (from book in context.Books where book.GenreType == genretype select book).ToList(); return(books); }
public IEnumerable <Book> GetAllBooks() { IEnumerable <Book> books; using (var context = new LibraryDBContext()) { books = context.Books.Include("Authors").ToList(); context.SaveChanges(); } return(books); }
public IEnumerable <Book> getByPublisher(string publisherID) { IEnumerable <BookRepository> bookrepos; var context = new LibraryDBContext(); { bookrepos = context.BookRepositories.Include("Book").Where(bookrepo => bookrepo.Publisher.PublisherID == publisherID).Select(book => book).ToList(); } IEnumerable <Book> books = bookrepos.Where(bookrepo => bookrepo.Publisher.PublisherID == publisherID).Select(bookrepo => bookrepo.Book); return(books); }
public IEnumerable <Book> GetByAuthor(string authorID) { //IEnumerable<Book> books = GetAllBooks().SelectMany(book => book.Authors.Where(author => author.AuthorID == name), (book, author) => book).ToList(); //return books; var context = new LibraryDBContext(); IEnumerable <Book> books = context.Books.Include("Authors").SelectMany(book => book.Authors.Where(author => author.AuthorID == authorID), (book, author) => book); context.SaveChanges(); return(books); }
public Author GetAuthorByID(string ID) { Author author; using (var context = new LibraryDBContext()) { IEnumerable <Author> authors = (from authorL in context.Authors where authorL.AuthorID == ID select authorL).ToList(); author = authors.FirstOrDefault(); } return(author); }
public Publisher GetPublisher(string name) { Publisher publisher; using (var context = new LibraryDBContext()) { IEnumerable <Publisher> publishers = from pblr in context.Publishers where pblr.Name.Contains(name) select pblr; publisher = publishers.FirstOrDefault(); } return(publisher); }
public Publisher GetPublisherByID(string ID) { Publisher publisher; using (var context = new LibraryDBContext()) { IEnumerable <Publisher> publishers = from pblr in context.Publishers where pblr.PublisherID == ID select pblr; publisher = publishers.FirstOrDefault(); } return(publisher); }
public string AddBook(BookDTO bookDTO) { if (string.IsNullOrEmpty(bookDTO.GenreType)) { throw new InvalidBookException("Invalid GenreType"); } if (string.IsNullOrEmpty(bookDTO.Title)) { throw new InvalidBookException("Invalid Title"); } if (bookDTO.publisherID == null) { throw new InvalidBookException("Invalid Publisher"); } if (bookDTO.AuthorIDlist.Count() == 0) { throw new InvalidBookException("Book Must contain atleast one author"); } Book book; using (var context = new LibraryDBContext()) { book = context.Books.Include("Authors").Where(bookL => bookL.Title == bookDTO.Title).Select(bookL => bookL).SingleOrDefault(); if (book == null) { book = new Book(); book.Title = bookDTO.Title; book.GenreType = bookDTO.GenreType; book.BookID = bookDTO.generateID(); } foreach (var authorid in bookDTO.AuthorIDlist) { Author author = context.Authors.Include("Books").Where(authorL => authorL.AuthorID == authorid).Select(authorL => authorL).Single(); book.Authors.Add(author); } BookRepository bookrepo = new BookRepository(); bookrepo.Book = book; Publisher publisher = context.Publishers.Where(publisherL => publisherL.PublisherID == bookDTO.publisherID).Select(publisherL => publisherL).Single(); bookrepo.Publisher = publisher; bookrepo.Edition = bookDTO.Edition; bookrepo.NumberOfCopies = bookDTO.NumberOfCopies; context.BookRepositories.Add(bookrepo); context.SaveChanges(); } return(book.BookID); }
/// <summary> /// To get the book Repositories of the given book /// </summary> /// <param name="BookID"></param> /// <returns></returns> public IEnumerable <BookRepository> getBookRepositories(string BookID) { IEnumerable <BookRepository> bookrepositories; using (var context = new LibraryDBContext()) { bookrepositories = (from bookrepo in context.BookRepositories where bookrepo.BookID == BookID select bookrepo).ToList(); context.SaveChanges(); } return(bookrepositories); }
public bool AddEdition(string BookID, string PublisherID, string edition, int numberOfCopies) { using (var context = new LibraryDBContext()) { BookRepository bookrepo = new BookRepository(); bookrepo.Book = context.Books.Include("Authors").Where(book => book.BookID == BookID).Single(); bookrepo.Publisher = context.Publishers.Where(publisher => publisher.PublisherID == PublisherID).Single(); bookrepo.Edition = edition; bookrepo.NumberOfCopies = numberOfCopies; context.BookRepositories.Add(bookrepo); context.SaveChanges(); } return(true); }
public bool deleteBookwithAllEditions(string bookID) { var context = new LibraryDBContext(); Book book = context.Books.Include("Authors").Where(bookL => bookL.BookID == bookID) .Select(bookL => bookL) .SingleOrDefault(); if (book != null) { context.Books.Remove(book); context.SaveChanges(); return(true); } else { return(false); } }
public bool deleteBookRepository(string bookID, string Edition) { var context = new LibraryDBContext(); BookRepository bookRepository = context.BookRepositories.Include("Book") .Where(bookrepo => (bookrepo.BookID == bookID && bookrepo.Edition == Edition)) .Select(bookrepo => bookrepo) .SingleOrDefault(); if (bookRepository != null) { context.BookRepositories.Remove(bookRepository); context.SaveChanges(); return(true); } else { return(false); } }
public string AddAuthor(AuthorDTO authorDTO) { if (string.IsNullOrEmpty(authorDTO.FirstName)) { throw new InvalidAuthorException("Invalid FirstName"); } if (string.IsNullOrEmpty(authorDTO.LastName)) { throw new InvalidAuthorException("Invalid LastName"); } Author author = new Author(); author.firstName = authorDTO.FirstName; author.lastName = authorDTO.LastName; author.AuthorID = authorDTO.generateID(); using (var context = new LibraryDBContext()) { context.Authors.Add(author); context.SaveChanges(); } return(author.AuthorID); }
public string AddPublisher(PublisherDTO publisherDTO) { if (string.IsNullOrEmpty(publisherDTO.Name)) { throw new InvalidPublisherException("INVALID PUBLISHER NAME "); } if (publisherDTO.ContactNumber == 0) { throw new InvalidPublisherException("INVALID CONTACT NUMBER"); } Publisher publisher = new Publisher(); publisher.Name = publisherDTO.Name; publisher.ContactNumber = publisherDTO.ContactNumber; publisher.PublisherID = publisherDTO.generateID(); using (var context = new LibraryDBContext()) { context.Publishers.Add(publisher); context.SaveChanges(); } return(publisher.PublisherID); }