コード例 #1
0
        private void TakeABook()
        {
            Console.Clear();

            var isBookFind = false;

            while (!isBookFind)
            {
                Console.WriteLine("Please, print the book's name.");
                var name = Console.ReadLine();
                Console.WriteLine("Please, print the book's author.");
                var author = Console.ReadLine();
                var isAnyAuthorBookWithTheName =
                    BooksList.Any(book => book.Name == name && book.Author == author && book.Count > 0);

                if (isAnyAuthorBookWithTheName)
                {
                    Console.WriteLine("Please, take your book.");
                    var bookIndex =
                        BooksList.FindIndex(book => book.Name == name && book.Author == author && book.Count > 0);
                    BooksList[bookIndex].Count--;

                    if (BooksList[bookIndex].PopularityIndex <= Book.MaxPopularityIndex)
                    {
                        BooksList[bookIndex].PopularityIndex++;
                    }

                    isBookFind = true;
                }
                else
                {
                    Console.WriteLine("There isn't any book with the name of the author. Please, try again.");
                }
            }
        }
コード例 #2
0
        private void AddABook()
        {
            Console.Clear();
            Console.WriteLine("Please, print the book's name.");
            var name = Console.ReadLine();

            Console.WriteLine("Please, print the book's author.");
            var author = Console.ReadLine();

            var isAnyAuthorBookWithTheName = BooksList.Any(book => book.Name == name && book.Author == author);

            if (isAnyAuthorBookWithTheName)
            {
                var bookIndex = BooksList.FindIndex(book => book.Name == name && book.Author == author);
                BooksList[bookIndex].Count++;
                Console.WriteLine("Thank you for adding one more exemplar.");
            }
            else
            {
                var generes = Enum.GetNames(typeof(Genere));
                Console.WriteLine("Please, choose the book's genere.");
                for (int i = 0; i < generes.Length; i++)
                {
                    Console.WriteLine("{0} : {1}", (i + 1), generes[i]);
                }

                var genere = Genere.Detective;

                switch (Console.ReadLine())
                {
                case "1":
                    genere = Genere.Fantasy;
                    break;

                case "2":
                    genere = Genere.Detective;
                    break;

                case "3":
                    genere = Genere.Romance;
                    break;
                }

                Console.WriteLine("Please, print the book's year of publication.");
                var yearOfPublication = int.Parse(Console.ReadLine());
                Console.WriteLine("Please, print the book's number of pages.");
                var numberOfPages = int.Parse(Console.ReadLine());

                var newBook = new Book(name, author, genere, yearOfPublication, numberOfPages, 1, 1);
                BooksList.Add(newBook);
            }

            Console.WriteLine("Thank you for adding the book!");
            Console.WriteLine("Please, press any key to continue...");
            Console.ReadLine();
        }
コード例 #3
0
        private void FindBookByTheName()
        {
            Console.Clear();
            Console.WriteLine("Please, print the book's name.");
            var name = Console.ReadLine();
            var isAnyBookWithTheName = BooksList.Any(book => book.Name == name && book.Count > 0);

            if (isAnyBookWithTheName)
            {
                var findedBook = BooksList.Single(book => book.Name == name && book.Count > 0);
                Console.WriteLine(findedBook);
            }
            else
            {
                Console.WriteLine("There isn't any book with the name.");
            }
        }
コード例 #4
0
        private void FindBooksByTheAuthor()
        {
            Console.Clear();
            Console.WriteLine("Please, print the book's author.");
            var author          = Console.ReadLine();
            var isAnyAuthorBook = BooksList.Any(book => book.Author == author && book.Count > 0);

            if (isAnyAuthorBook)
            {
                var findedBooks = BooksList.Where(book => book.Author == author && book.Count > 0);

                foreach (var findedBook in findedBooks)
                {
                    Console.WriteLine(findedBook);
                }
            }
            else
            {
                Console.WriteLine("There isn't any book of the author.");
            }
        }
コード例 #5
0
        private void FindTheBookByTheNameAndTheAuthor()
        {
            Console.Clear();
            Console.WriteLine("Please, print the book's name.");
            var name = Console.ReadLine();

            Console.WriteLine("Please, print the book's author.");
            var author = Console.ReadLine();
            var isAnyAuthorBookWithTheName = BooksList.Any(book => book.Name == name && book.Author == author && book.Count > 0);

            if (isAnyAuthorBookWithTheName)
            {
                var findedBook = BooksList.Single(book => book.Name == name && book.Author == author && book.Count > 0);
                Console.WriteLine(findedBook);
            }
            else
            {
                Console.WriteLine("There isn't any book with the name of the author.");
            }

            Console.WriteLine("Please, press any key to continue...");
            Console.ReadLine();
        }