コード例 #1
0
        public static void ProceedToAdd()
        {
            string username;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("----ADD BOOK----" + "\n" + "\n" + ">Type your username");
                username = Console.ReadLine();
                if (!username.Trim().Equals(string.Empty))
                {
                    break;
                }
            }

            Admin admin = rental.TryPickAdminByUsername(username);

            if (admin == null)
            {
                NoAdminCase();
                return;
            }

            Console.Clear();
            Console.WriteLine("----ADD BOOK----");
            Console.WriteLine();
            Console.WriteLine("Hi, Admin " + admin.Name + ", id: " + admin.Id + "\n" + ">Input book name: ");
            string bookname = Console.ReadLine();

            Console.WriteLine("OK, now input authors delimited by coma");
            string        astr    = Console.ReadLine();
            List <Author> authors = new List <Author>();

            foreach (string str in astr.Split(","))
            {
                authors.Add(new Author(Guid.NewGuid(), str));
            }

            Console.WriteLine(rental.TryAddBook(admin.CreateBook(Guid.NewGuid(), bookname, authors)) ? "OK, added a new book" : "Book already exists");
            Console.WriteLine("\n" + "Press any key to proceed to menu...");
            while (true)
            {
                if (Console.ReadKey() != null)
                {
                    break;
                }
            }
        }