コード例 #1
0
        /// <summary>
        /// This method is for adding the new edition of the already available book
        /// </summary>
        public static void AddEditionOption()
        {
            Book book;

            while (true)
            {
                Console.WriteLine("Enter Title of the Book");
                string bookname = Console.ReadLine();
                book = bookmanager.GetByTitle(bookname);
                if (book == null)
                {
                    Console.Write("\n No Book Found ");
                }
                else
                {
                    break;
                }
            }
            BookRepositoryDTO bookRepoDTO = new BookRepositoryDTO();

            Console.WriteLine("Enter edition of the book");
            bookRepoDTO.Edition = Console.ReadLine();
            Console.WriteLine("Enter number of Books");
            int numberofbooks = int.Parse(Console.ReadLine());

            bookRepoDTO.PublishedDate = DateTime.Now;
            bookRepoDTO.BookID        = book.ID;
            if (bookRepositoryManager.Add(book.ID, bookRepoDTO) != null)
            {
                Console.WriteLine("Book Added Successfully");
            }
        }
        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);
        }
コード例 #4
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();
            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");
            }
        }