コード例 #1
0
        /// <summary>
        /// This method is for adding the new edition of the already available book
        /// </summary>
        public static void AddEditionOption()
        {
            Console.WriteLine("Enter name of the Book");
            string bookname = Console.ReadLine();
            Book   book     = bookmanager.getBook(bookname);

            Console.WriteLine("Enter edition of the book");
            string edition = Console.ReadLine();

            Console.WriteLine("Enter number of Books");
            int numberofbooks = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter name of the publisher");
            string    name      = Console.ReadLine();
            Publisher publisher = publishermanager.GetPublisher(name);

            if (publisher == null)
            {
                PublisherDTO publisherdto = new PublisherDTO();
                publisherdto.Name = name;
                Console.WriteLine("Enter contact number");
                publisherdto.ContactNumber = long.Parse(Console.ReadLine());
                string publisherID = publishermanager.AddPublisher(publisherdto);
                bookmanager.AddEdition(book.BookID, publisherID, edition, numberofbooks);
            }
            if (bookmanager.AddEdition(book.BookID, publisher.PublisherID, edition, numberofbooks))
            {
                Console.WriteLine("Book added successfully");
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <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();

            Console.Write("\nEnter the title of the book : ");
            bookdto.Title = Console.ReadLine();

            Console.Write("\nEnter GenreType : ");
            bookdto.GenreType = Console.ReadLine();
            while (true)
            {
                Console.Write("\nEnter Author firstName :");
                authorDTO.FirstName = Console.ReadLine();
                Console.Write("\nEnter Author lastName :");
                authorDTO.LastName = Console.ReadLine();

                Author author = authormanager.GetAuthorByName(authorDTO.FirstName);
                if (author == null)
                {
                    bookdto.AuthorIDlist.Add(authormanager.AddAuthor(authorDTO));
                }
                else
                {
                    bookdto.AuthorIDlist.Add(author.AuthorID);
                }
                Console.Write("\n Do you want to enter more authors : ");
                if (string.Equals("No", Console.ReadLine(), StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }
            }

            Console.Write("\n Enter name of the Publisher : ");
            publisherDTO.Name = Console.ReadLine();
            Console.Write("\n Enter mobile number of the publisher : ");
            publisherDTO.ContactNumber = long.Parse(Console.ReadLine());

            Publisher publisher = publishermanager.GetPublisher(publisherDTO.Name);

            if (publisher == null)
            {
                bookdto.publisherID = publishermanager.AddPublisher(publisherDTO);
            }
            else
            {
                bookdto.publisherID = publisher.PublisherID;
            }
            Console.Write("\n Enter edition of the Book : ");
            bookdto.Edition = Console.ReadLine();
            Console.Write("\n Enter number of copies of the book : ");
            int numberofbooks = 0;

            int.TryParse(Console.ReadLine(), out numberofbooks);
            bookdto.NumberOfCopies = numberofbooks;

            if (bookmanager.AddBook(bookdto) != null)
            {
                Console.WriteLine("Book added successfully");
            }
            else
            {
                Console.WriteLine("SOMETHING WENT WRONG IN ADDING BOOK");
            }
        }