/// <summary> /// Processes the input of the user for adding a book to the database /// </summary> /// <param name="admin">Takes a user with admin priviliges</param> private static void AddBook(User admin) { var bookInformation = AdminView.AddBook(); if (api.AddBook( admin.Id, Convert.ToInt32(bookInformation["Antal"]), bookInformation["Titel"], bookInformation["Författare"], Convert.ToInt32(bookInformation["Pris"]))) { var book = api.GetBooks(bookInformation["Titel"])[0]; ChangeCategory(book, admin); } else { SharedError.Failed(); } }
/// <summary> /// Method for getting input and searching for a book /// </summary> /// <returns>A specific book</returns> public static Book SearchForBook() { WebShopApi api = new WebShopApi(); Console.Clear(); BookView.SearchForBook(); var searchKeyword = SharedController.GetSearchInput(); if (searchKeyword.ToLower() == "x") { return(null); } var listWithMatchingBooks = api.GetBooks(searchKeyword); if (listWithMatchingBooks.Count > 0) { Console.Clear(); BookView.ListAllBooks(listWithMatchingBooks); var input = SharedController.GetAndValidateInput(); if (input.validatedInput != 0 && input.validatedInput <= listWithMatchingBooks.Count) { return(api.GetBook(listWithMatchingBooks[input.validatedInput - 1].Id)); } else { SharedError.PrintWrongInput(); return(null); } } else { SharedError.NothingFound(); return(null); } }