public Author Get(string Name) { var context = new LibraryDBContext(); Author author = context.Authors.SingleOrDefault(authorL => (authorL.FirstName + authorL.LastName).Contains(Name)); return(author); }
public IEnumerable <Author> GetAll() { var context = new LibraryDBContext(); var authors = context.Authors.Include("Books").ToList(); return(authors); }
public IEnumerable <Book> GetAll() { var context = new LibraryDBContext(); var books = context.Books.ToList(); return(books); }
public Author GetByID(string ID) { var context = new LibraryDBContext(); Author author = context.Authors.Include("Books").SingleOrDefault(authorL => authorL.ID == ID); return(author); }
public bool Update(string BookID, BookDTO dto) { var context = new LibraryDBContext(); Book book = context.Books.SingleOrDefault(bookL => bookL.ID == BookID); if (book == null) { throw new InvalidBookException("BOOK NOT FOUND"); } if (dto.Title != null) { book.Title = dto.Title; } if (dto.GenreType != null) { book.GenreType = dto.GenreType; } if (dto.BookRepositoryDTO != null) { dto.BookRepositoryDTO.BookID = book.ID; if (!bookrepositorymanager.Update(book.ID, dto.BookRepositoryDTO.Edition, dto.BookRepositoryDTO)) { throw new Exception("SOMETHING WENT WRONG"); } } context.SaveChanges(); return(true); }
public BookRepository Get(string BookID, string Edition) { var context = new LibraryDBContext(); BookRepository bookrepo = context.BookRepository.SingleOrDefault(record => record.BookID == BookID && record.Edition == Edition); return(bookrepo); }
public IEnumerable <Publisher> GetAll() { var context = new LibraryDBContext(); var publishers = context.Publishers.Include("Books").ToList(); return(publishers); }
public Publisher GetByID(string ID) { var context = new LibraryDBContext(); Publisher publisher = context.Publishers.SingleOrDefault(publisherL => publisherL.ID == ID); return(publisher); }
public Publisher Get(string Name) { var context = new LibraryDBContext(); Publisher publisher = context.Publishers.SingleOrDefault(publisherL => publisherL.Name == Name); return(publisher); }
public string Add(AuthorDTO dto) { if (string.IsNullOrEmpty(dto.FirstName)) { throw new InvalidAuthorException("INVALID AUTHOR FIRSTNAME"); } if (string.IsNullOrEmpty(dto.LastName)) { throw new InvalidAuthorException(" INVALID AUTHOR LASTNAME"); } Author author; var context = new LibraryDBContext(); author = context.Authors.SingleOrDefault(authorL => (authorL.FirstName + authorL.LastName) == (dto.FirstName + dto.LastName)); if (author == null) { author = new Author(); author.FirstName = dto.FirstName; author.LastName = dto.LastName; author.ID = dto.generateID(); context.Authors.Add(author); context.SaveChanges(); return(author.ID); } else { return(author.ID); } }
public string Add(PublisherDTO dto) { if (string.IsNullOrWhiteSpace(dto.Name)) { throw new InvalidPublisherException("INVALID PUBLISHER NAME"); } if (dto.ContactNumber == 0) { throw new InvalidPublisherException("INVALID PUBLISHER CONTACT NUMBER"); } Publisher publisher; var context = new LibraryDBContext(); publisher = context.Publishers.SingleOrDefault(publisherL => publisherL.Name == dto.Name); if (publisher == null) { publisher = new Publisher(); publisher.Name = dto.Name; publisher.ContactNumber = dto.ContactNumber; publisher.ID = dto.generateID(); context.Publishers.Add(publisher); context.SaveChanges(); return(publisher.ID); } else { return(publisher.ID); } }
public Book GetByTitle(string title) { var context = new LibraryDBContext(); Book book = context.Books.Include("Authors") .SingleOrDefault(bookL => bookL.Title == title); return(book); }
public IEnumerable <BookRepository> Get(string BookID) { var context = new LibraryDBContext(); var books = context.BookRepository.ToList() .Where(bookRepo => bookRepo.BookID == BookID); return(books); }
public Book GetByID(string ID) { var context = new LibraryDBContext(); Book book = context.Books.Include("Authors") .ToList() .SingleOrDefault(bookL => bookL.ID == ID); return(book); }
public IEnumerable <Book> GetByPublisher(string ID) { var context = new LibraryDBContext(); var books = context.Books.Include("Authors") .ToList() .Where(book => book.Publisher.ID == ID); return(books); }
public IEnumerable <Book> GetByGenre(string GenreType) { var context = new LibraryDBContext(); var books = context.Books.Include("Authors") .ToList() .Where(book => book.GenreType.ToLower().Contains(GenreType.ToLower())); return(books); }
public IEnumerable <Book> GetByAuthor(string ID) { var context = new LibraryDBContext(); var books = from book in context.Books.Include("Authors") from author in book.Authors where author.ID == ID select book; return(books); }
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.publisherDTO == null) { throw new InvalidBookException("Invalid Publisher"); } if (bookDTO.AuthorDTOlist.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.ID = bookDTO.generateID(); foreach (var authordto in bookDTO.AuthorDTOlist) { string authorID = authormanager.Add(authordto); Author author = context.Authors.Include("Books").Where(authorL => authorL.ID == authorID).Select(authorL => authorL).Single(); book.Authors.Add(author); } string publisherID = publishermanager.Add(bookDTO.publisherDTO); Publisher publisher = context.Publishers.Where(publisherL => publisherL.ID == publisherID).Select(publisherL => publisherL).Single(); book.Publisher = publisher; context.Books.Add(book); context.SaveChanges(); } bookDTO.BookRepositoryDTO.BookID = book.ID; bookrepositorymanager.Add(book.ID, bookDTO.BookRepositoryDTO); } return(book.ID); }
public bool Delete(string BookID, string Edition) { var context = new LibraryDBContext(); var bookRepo = context.BookRepository.ToList().SingleOrDefault(bookrepo => bookrepo.BookID == BookID && bookrepo.Edition == Edition); if (bookRepo == null) { throw new InvalidBookException("Book Does not exist"); } context.BookRepository.Remove(bookRepo); context.SaveChanges(); return(true); }
public bool DeleteByID(string ID) { var context = new LibraryDBContext(); var author = context.Authors.SingleOrDefault(authorL => authorL.ID == ID); if (author == null) { throw new InvalidAuthorException("AUTHOR NOT FOUND"); } context.Authors.Remove(author); context.SaveChanges(); return(true); }
public bool DeleteByID(string ID) { var context = new LibraryDBContext(); Publisher publisher = context.Publishers.SingleOrDefault(publisherL => publisherL.ID == ID); if (publisher == null) { throw new InvalidPublisherException("PUBLISHER NOT FOUND"); } context.Publishers.Remove(publisher); context.SaveChanges(); return(true); }
public bool Delete(string Name) { var context = new LibraryDBContext(); Author author = context.Authors.SingleOrDefault(authorL => (authorL.FirstName + authorL.LastName).Contains(Name)); if (author == null) { throw new InvalidPublisherException("AUTHOR NOT FOUND"); } else { context.Authors.Remove(author); context.SaveChanges(); } return(true); }
public bool Delete(string ID) { var context = new LibraryDBContext(); Book book = context.Books.SingleOrDefault(bookL => bookL.ID == ID); if (book == null) { throw new InvalidBookException("BOOK NOT FOUND"); } else { context.Books.Remove(book); } context.SaveChanges(); return(true); }
public BookRepository Add(string BookID, BookRepositoryDTO bookRepositoryDTO) { var context = new LibraryDBContext(); Book book = context.Books.Include("Publisher").ToList() .SingleOrDefault(bookL => bookL.ID == BookID); BookRepository bookRepo = new BookRepository(); bookRepo.Publisher = book.Publisher; bookRepo.Book = book; if (bookRepositoryDTO.NumberOfCopies == 0) { throw new InvalidBookException("NUMBER OF COPIES MUST BE GREATER THAN ZERO"); } else { bookRepo.NumberOfCopies = bookRepositoryDTO.NumberOfCopies; } if (bookRepositoryDTO.Edition == null) { throw new InvalidBookException("INVALID BOOK EDITION"); } else { bookRepo.Edition = bookRepositoryDTO.Edition; } if (bookRepositoryDTO.Price == 0) { throw new InvalidBookException("INVALID PRICE"); } else { bookRepo.Price = bookRepositoryDTO.Price; } bookRepo.PublishedDate = DateTime.Now; //if (bookRepositoryDTO.PublishedDate == null) // throw new InvalidBookException("INVALID pUBLISHED DATE"); //else // bookRepo.PublishedDate = bookRepositoryDTO.PublishedDate; context.BookRepository.Add(bookRepo); book.BookRepositories.Add(bookRepo); context.SaveChanges(); return(bookRepo); }
public bool Update(string BookID, string Edition, BookRepositoryDTO bookRepoDTO) { var context = new LibraryDBContext(); var bookRepo = context.BookRepository.SingleOrDefault(repo => repo.BookID == BookID && repo.Edition == Edition); if (bookRepo == null) { return(false); } if (bookRepoDTO.NumberOfCopies != 0) { bookRepo.NumberOfCopies = bookRepoDTO.NumberOfCopies; } if (bookRepoDTO.Price != 0) { bookRepo.Price = bookRepoDTO.Price; } context.SaveChanges(); return(true); }
public bool Delete(string ID, string Edition) { var context = new LibraryDBContext(); Book book = context.Books.SingleOrDefault(bookL => bookL.ID == ID); if (book == null) { throw new InvalidBookException("BOOK NOT FOUND"); } else { bookrepositorymanager.Delete(ID, Edition); if (book.BookRepositories == null || book.BookRepositories.Count == 0) { context.Books.Remove(book); } context.SaveChanges(); } return(true); }
public bool Update(string ID, PublisherDTO dto) { var context = new LibraryDBContext(); Publisher publisher = context.Publishers.SingleOrDefault(publisherL => publisherL.ID == ID); if (publisher == null) { throw new InvalidPublisherException("PUBLISHER NOT FOUND"); } if (dto.Name != null) { publisher.Name = dto.Name; } if (dto.ContactNumber != 0) { publisher.ContactNumber = dto.ContactNumber; } context.SaveChanges(); return(true); }
public bool Update(AuthorDTO dto) { var context = new LibraryDBContext(); Author author = context.Authors.SingleOrDefault(authorL => (authorL.FirstName + authorL.LastName).Contains(dto.FirstName)); if (author == null) { throw new InvalidPublisherException("AUTHOR NOT FOUND"); } if (dto.FirstName != null) { author.FirstName = dto.FirstName; } if (dto.LastName != null) { author.LastName = dto.LastName; } context.SaveChanges(); return(true); }