Ejemplo n.º 1
0
        /// <summary>
        /// Method for changing the price of a book
        /// </summary>
        /// <param name="admin">Takes a user with admin priviliges</param>
        /// <param name="book">Takes a book to change price on</param>
        private static void ChangePrice(User admin, Book book)
        {
            var continueLoop = true;

            do
            {
                AdminView.ChangePrice();
                var input = InputHelper.InputFreeText();
                if (string.IsNullOrEmpty(input))
                {
                    SharedError.EmptyInput();
                    continue;
                }
                bool convertedSuccess = int.TryParse(input, out int price);
                if (convertedSuccess && price >= 0)
                {
                    if (book.Price != price)
                    {
                        book.Price = price;
                        api.UpdateBook(admin.Id, book.Id, book.Title, book.Author, book.Price);
                        continueLoop = false;
                    }
                }
                else
                {
                    SharedError.PrintWrongInput();
                }
            } while (continueLoop);
        }