Exemplo n.º 1
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);

                if (ValidatorHelper.ValidateBook(newBook))
                {
                    BooksList.Add(newBook);
                }
            }
        }
Exemplo n.º 2
0
        private void FillUsersHashSet()
        {
            var firstUser  = new User("Yevhen", "1111");
            var secondUser = new User("Katy", "22222");
            var thirdUser  = new User("", "");

            UsersHashSet = new HashSet <User>();

            if (ValidatorHelper.ValidateUser(firstUser))
            {
                UsersHashSet.Add(firstUser);
            }

            if (ValidatorHelper.ValidateUser(secondUser))
            {
                UsersHashSet.Add(secondUser);
            }

            if (ValidatorHelper.ValidateUser(thirdUser))
            {
                UsersHashSet.Add(thirdUser);
            }
        }