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 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); }
/// <summary> /// This method reads the data of the book and sends the data to dto classes and call addbook method in bookmanager /// </summary> public static void AddBookOption() { BookDTO bookDTO = new BookDTO(); AuthorDTO authorDTO = new AuthorDTO(); PublisherDTO publisherDTO = new PublisherDTO(); BookRepositoryDTO bookRepoDTO = new BookRepositoryDTO(); Console.Write("\nEnter Title : "); bookDTO.Title = Console.ReadLine(); while (true) { Console.WriteLine("1.Science&Technology 2.Romance 3.Literature 4.Biography 5.History"); Console.Write("\nSelect GenreType : "); int genre = 0; int.TryParse(Console.ReadLine(), out genre); if (genre == 0 || genre < 0 || genre > 5) { Console.WriteLine("Please enter correct value"); continue; } else { switch (genre) { case 1: bookDTO.GenreType = "Science&Technology"; break; case 2: bookDTO.GenreType = "Romance"; break; case 3: bookDTO.GenreType = "Literature"; break; case 4: bookDTO.GenreType = "Biography"; break; case 5: bookDTO.GenreType = "History"; break; default: Console.WriteLine("Enter correct value"); break; } break; } } while (true) { Console.Write("\nEnter Author FirstName :"); authorDTO.FirstName = Console.ReadLine(); Console.Write("\nEnter Author LastName :"); authorDTO.LastName = Console.ReadLine(); bookDTO.AuthorDTOlist.Add(authorDTO); //Author author = authormanager.Get(authorDTO.FirstName); //if (author == null) //{ // bookDTO.AuthorIDlist.Add(authormanager.Add(authorDTO)); //} //else // bookDTO.AuthorIDlist.Add(author.ID); Console.Write("\n Do you want to enter more authors Yes/No : "); if (string.Equals("No", Console.ReadLine(), StringComparison.CurrentCultureIgnoreCase)) { break; } } Console.Write("\n Enter Publisher Name : "); publisherDTO.Name = Console.ReadLine(); Console.Write("\n Enter Publisher MoblieNumber : "); publisherDTO.ContactNumber = long.Parse(Console.ReadLine()); bookDTO.publisherDTO = publisherDTO; //Publisher publisher = publishermanager.Get(publisherDTO.Name); //if (publisher == null) //{ // bookDTO.publisherID = publishermanager.Add(publisherDTO); //} //else // bookDTO.publisherID = publisher.ID; Console.Write("\n Enter Edition : "); bookRepoDTO.Edition = Console.ReadLine(); Console.Write("\n Enter Price : "); bookRepoDTO.Price = Double.Parse(Console.ReadLine()); Console.Write("\n Enter Number of Copies : "); int numberofbooks = 0; int.TryParse(Console.ReadLine(), out numberofbooks); bookRepoDTO.NumberOfCopies = numberofbooks; bookDTO.BookRepositoryDTO = bookRepoDTO; if (bookmanager.AddBook(bookDTO) != null) { Console.WriteLine("BOOK ADDED SUCCESSFULLY"); } else { Console.WriteLine("SOMETHING WENT WRONG IN ADDING BOOK"); } }