Пример #1
0
        public Options Execute(ICommandArgs commandArgs)
        {
            var option = commandArgs.MultipleChoice(title: "Login to System:", options: new List <Options>
            {
                Options.LoginMenu_Login,
                Options.LoginMenu_Register,
                Options.Quit
            });
            string username;

            switch (option)
            {
            case Options.LoginMenu_Login:
                Console.WriteLine("Enter your username:"******"Wrong username!");
                    Console.ReadKey();
                    return(Options.LoginMenu);
                }

                return(Options.HomeMenu);

            case Options.LoginMenu_Register:
                Console.WriteLine("Enter your username");
                username = Console.ReadLine();
                commandArgs.Users.CreateAccount(username, AccountType.Member);
                commandArgs.Users.Login(username);
                return(Options.HomeMenu);
            }

            return(option);
        }
        public Options Execute(ICommandArgs commandArgs)
        {
            Console.WriteLine("Enter Username");
            var userName = Console.ReadLine();

            var user = commandArgs.Users.Accounts.Find(u => u.UserName == userName);

            var option = commandArgs.MultipleChoice(title: $"Edit user {user}", new List <Options>
            {
                Options.EditUser_ChangeUsername,
                Options.EditUser_ChangeUserType,
                Options.Quit
            });

            switch (option)
            {
            case Options.EditUser_ChangeUsername:
                Console.WriteLine("Enter new Username");
                var newUserName = Console.ReadLine();
                user.UserName = newUserName;
                break;

            case Options.EditUser_ChangeUserType:
                Console.WriteLine("Enter new userType");
                var newUserType = Console.ReadLine();
                user.Type = (AccountType)Enum.Parse(typeof(AccountType), newUserType);
                break;
            }

            return(Options.HomeMenu);
        }
        public Options Execute(ICommandArgs commandArgs)
        {
            Console.WriteLine("Write Username which you want to Register:");
            var registerUserName = Console.ReadLine();
            var user             = new Users();

            var option = commandArgs.MultipleChoice(title: $"Register Username {registerUserName}", new List <string>
            {
                "Register new Member",
                "Register new Librarian"
            });

            switch (option)
            {
            case "Register new Member":
                var newUsernameMember = commandArgs.Users.CreateAccount(registerUserName, AccountType.Member);
                user.Accounts.Add(newUsernameMember);
                break;

            case "Register new Librarian":
                var newUsernameLibrarian = commandArgs.Users.CreateAccount(registerUserName, AccountType.Librarian);
                user.Accounts.Add(newUsernameLibrarian);
                break;
            }

            Console.WriteLine($"Member with name {registerUserName} was create");

            return(Options.HomeMenu);
        }
        public Options Execute(ICommandArgs commandArgs)
        {
            var options = commandArgs.MultipleChoice(title: "Search in catalog", options: new List <Options>
            {
                Options.SearchInCatalog_ByTitle,
                Options.SearchInCatalog_ByAuthor,
                Options.SearchInCatalog_BySubject,
                Options.SearchInCatalog_SearchByPublishDate,
                Options.Quit
            });
            List <Book> books = null;

            switch (options)
            {
            case Options.SearchInCatalog_ByTitle:
                Console.WriteLine("Please enter title:");
                var title = Console.ReadLine();
                books = commandArgs.Library.Catalog.SearchByTitle(title);
                break;

            case Options.SearchInCatalog_ByAuthor:
                Console.WriteLine("Please enter author:");
                var author = Console.ReadLine();
                books = commandArgs.Library.Catalog.SearchByAuthor(author);
                break;

            case Options.SearchInCatalog_BySubject:
                Console.WriteLine("Please enter subject:");
                var subject = Console.ReadLine();
                books = commandArgs.Library.Catalog.SearchBySubject(subject);
                break;

            case Options.SearchInCatalog_SearchByPublishDate:
                Console.WriteLine("Please enter publish date:");
                var publishDate = Console.ReadLine();
                books = commandArgs.Library.Catalog.SearchByPublishDate(publishDate);
                break;
            }

            commandArgs.SelectedBook = commandArgs.MultipleChoice(title: "Book found", books);

            return(Options.HomeMenu);// BookMenu
        }
        public Options Execute(ICommandArgs commandArgs)
        {
            if (commandArgs.Library.System.BookLendings.Count(u => u.User == commandArgs.Users.CurrentAccount) == 5)
            {
                Console.WriteLine("You cannot take more than 5 books");
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            Console.WriteLine("Enter ISBN of the book you want:");
            var bookIsbn = Console.ReadLine();

            var book = commandArgs.Library.Books.FirstOrDefault(b => b.ISBN == bookIsbn);

            if (book == null)
            {
                Console.WriteLine($"Book with the following ISBN: {bookIsbn} was not found");
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            var bookReservation = new BookReservation();
            var user            = commandArgs.Users.CurrentAccount;

            if (!commandArgs.Library.LendBook(user, book))
            {
                var option = commandArgs.MultipleChoice(title: "The book has no other copies left!" +
                                                        " Do you want to reserve?", new List <String>
                {
                    "Reserve",
                    "Cancel"
                });
                if (option == "Reserve")
                {
                    if (commandArgs.Library.System.BookLendings.Count(b => b.User == commandArgs.Users.CurrentAccount) == 5)
                    {
                        Console.WriteLine("You cannot reserve more than 5 books");
                        Console.ReadKey();
                        return(Options.HomeMenu);
                    }
                    commandArgs.Library.ReserveBook(user, book);
                    Console.WriteLine($"You reserved book: {book} {DateTime.Now}");
                    Console.ReadKey();
                }
            }
            else
            {
                Console.WriteLine($"You checked out book: {book} {DateTime.Now}");
                Console.ReadKey();
            }
            return(Options.HomeMenu);
        }
        public Options Execute(ICommandArgs commandArgs)
        {
            Console.WriteLine("Enter ISBN of book");
            var isbnInput = Console.ReadLine();

            var oldBook = commandArgs.Library.Books.FirstOrDefault(b => b.ISBN == isbnInput);

            if (oldBook == null)
            {
                Console.WriteLine($"Book with ISBN - {isbnInput} does not exist");
                Console.ReadKey();
                return(Options.BookMenu);
            }


            var options = commandArgs.MultipleChoice(title: $"Found book {oldBook}", new List <string>
            {
                "Edit Title",
                "Edit Publisher",
                "Edit Subject"
            });


            var newBook = new Book();

            switch (options)
            {
            case "Edit Title":
                var title = Console.ReadLine();
                newBook.Title = title;
                commandArgs.Library.EditBook(oldBook, newBook);
                break;

            case "Edit Publishers":
                var publisher = Console.ReadLine();
                newBook.Publishers = publisher;
                commandArgs.Library.EditBook(oldBook, newBook);
                break;

            case "Edit Subject":
                var subject = Console.ReadLine();
                newBook.Subject = subject;
                commandArgs.Library.EditBook(oldBook, newBook);
                break;
            }
            Console.Clear();
            Console.WriteLine($"Edited book {oldBook}");
            Console.ReadKey();

            return(Options.HomeMenu);
        }
Пример #7
0
        public Options Execute(ICommandArgs commandArgs)
        {
            var user    = commandArgs.Users.CurrentAccount;
            var options = new List <Options>();

            if (user.CanAddBook)
            {
                options.Add(Options.AddBook);
            }
            if (user.CanEditBook)
            {
                options.Add(Options.EditBook);
            }
            if (user.CanEditUsers)
            {
                options.Add(Options.EditUsers);
            }
            if (user.CanCheckOutBook)
            {
                options.Add(Options.CheckOutBook);
            }
            if (user.CanRegisterUsers)
            {
                options.Add(Options.RegisterUser);
            }
            if (user.CanRenewBook)
            {
                options.Add(Options.RenewBook);
            }
            if (user.CanReturnBook)
            {
                options.Add(Options.ReturnBook);
            }
            if (user.CanSearchTheCatalogue)
            {
                options.Add(Options.SearchInCatalog);
            }

            options.Add(Options.Quit);

            var option = commandArgs.MultipleChoice(title: "Home: ", options);

            return(option);
        }