/// <summary> /// Allows an admin user to add a book to category /// </summary> /// <param name="adminId"></param> private void AddBookToCategory(int adminId) { AdminView.AddBookCategory(); new Book().SearchBooksByTitle(); MessageViews.DisplaySelectMessage(); var bookId = InputHelper.ParseInput(); new Book().ViewAllCategories(); MessageViews.DisplaySelectMessage(); MessageViews.DisplayReturnMessage(); var categoryId = InputHelper.ParseInput(); if (categoryId == 0) { return; } if (bookId != 0 && categoryId != 0) { WebbShopAPI api = new WebbShopAPI(); var result = api.AddBookToCategory(adminId, bookId, categoryId); if (result) { MessageViews.DisplaySuccessMessage(); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows admin user to set the amount of a book /// </summary> /// <param name="adminId"></param> private void SetAmount(int adminId) { new Book().FindAllAvailableBooks(); AdminView.SetAmountPage(); MessageViews.DisplayReturnMessage(); var bookId = InputHelper.ParseInput(); if (bookId == 0) { return; } var newAmount = InputHelper.ParseInput(); WebbShopAPI api = new WebbShopAPI(); bool result = api.SetAmount(adminId, bookId, newAmount); if (result) { MessageViews.DisplaySuccessMessage(); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows an admin user to update an existing book /// </summary> /// <param name="adminId"></param> private void UpdateBook(int adminId) { new Book().FindAllAvailableBooks(); MessageViews.DisplaySelectMessage(); MessageViews.DisplayReturnMessage(); var bookId = InputHelper.ParseInput(); if (bookId == 0) { return; } AdminView.UpdateBookPage(); var title = Console.ReadLine(); var author = Console.ReadLine(); var price = InputHelper.ParseInput(); if (title != "" && author != "" && price != 0) { WebbShopAPI api = new WebbShopAPI(); bool result = api.UpdateBook(adminId, bookId, title, author, price); if (result) { MessageViews.DisplaySuccessMessage(); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows admin user to update an existing category /// </summary> /// <param name="adminId"></param> private void UpdateCategory(int adminId) { new Book().ViewAllCategories(); MessageViews.DisplaySelectMessage(); MessageViews.DisplayReturnMessage(); var categoryId = InputHelper.ParseInput(); if (categoryId == 0) { return; } AdminView.UpdateCategoryPage(); var genere = Console.ReadLine(); if (genere != "") { WebbShopAPI api = new WebbShopAPI(); var result = api.UpdateCategory(adminId, categoryId, genere); if (result) { MessageViews.DisplaySuccessMessage(); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows an admin user to see which customer bought the most books /// </summary> /// <param name="adminId"></param> private void ViewBestCustomer(int adminId) { WebbShopAPI api = new WebbShopAPI(); var customerId = api.BestCustomer(adminId); if (customerId != 0) { AdminView.DisplayBestCustomer(customerId); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows admin user to view the sum of all sold books /// </summary> /// <param name="adminId"></param> private void ViewTotalIncome(int adminId) { WebbShopAPI api = new WebbShopAPI(); var totalIncome = api.MoneyEarned(adminId); if (totalIncome != 0) { AdminView.DisplayMoneyEarned(totalIncome); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows you to view all available books /// </summary> public void FindAllAvailableBooks() { var listOfBooks = GetAllBooks(); if (listOfBooks.Count != 0) { var sortBookList = listOfBooks.OrderBy(b => b.ID).ToList(); BookViews.DisplayAvailableBooks(sortBookList); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows an admin user to view all sold books /// </summary> /// <param name="adminId"></param> private void ViewAllSoldItems(int adminId) { WebbShopAPI api = new WebbShopAPI(); var listOfSoldItems = api.SoldItems(adminId); if (listOfSoldItems != null) { AdminView.DisplaySoldItems(listOfSoldItems); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows you to view details for a specific book /// </summary> /// <param name="bookId"></param> public void ViewDetails(int bookId) { WebbShopAPI api = new WebbShopAPI(); var bookDetails = api.GetBook(bookId); if (bookDetails != string.Empty) { BookViews.DisplayDetails(bookDetails); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows you to view all book categories /// </summary> public void ViewAllCategories() { WebbShopAPI api = new WebbShopAPI(); var listOfCategories = api.GetCategories().ToList(); if (listOfCategories != null) { var sortCategoryList = listOfCategories.OrderBy(c => c.ID).ToList(); BookViews.DisplayCategoryList(sortCategoryList); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows an admin user to view all users /// </summary> /// <param name="adminId"></param> private void ViewAllUsers(int adminId) { WebbShopAPI api = new WebbShopAPI(); var listOfUsers = api.ListUsers(adminId); if (listOfUsers != null) { var sortUserList = listOfUsers.OrderBy(u => u.ID).ToList(); AdminView.DisplayUsers(sortUserList); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows you to search for a specific category /// </summary> public void SearchFunctionCategories() { BookViews.SearchPage(); var keyword = Console.ReadLine(); if (keyword != "") { WebbShopAPI api = new WebbShopAPI(); var listOfCategories = api.GetCategories(keyword).ToList(); if (listOfCategories != null) { BookViews.DisplayCategoryList(listOfCategories); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows admin user to add a new category /// </summary> /// <param name="adminId"></param> private void AddCategory(int adminId) { AdminView.AddCategoryPage(); var genere = Console.ReadLine(); if (genere != "") { WebbShopAPI api = new WebbShopAPI(); var result = api.AddCategory(adminId, genere); if (result) { MessageViews.DisplaySuccessMessage(); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows you to search for books based to title /// </summary> public void SearchBooksByTitle() { BookViews.SearchPage(); var keyword = Console.ReadLine(); if (keyword != "") { WebbShopAPI api = new WebbShopAPI(); var listOfBooks = api.GetBooks(keyword).ToList(); if (listOfBooks != null) { BookViews.DisplayBookList(listOfBooks); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows an admin user to find another user /// </summary> /// <param name="adminId"></param> private void FindUser(int adminId) { AdminView.SearchPage(); var keyword = Console.ReadLine(); if (keyword != "") { WebbShopAPI api = new WebbShopAPI(); var listOfUsers = api.FindUser(adminId, keyword); if (listOfUsers != null) { var sortUserList = listOfUsers.OrderBy(u => u.ID).ToList(); AdminView.DisplayUsers(sortUserList); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows an admin user to add a new book /// </summary> /// <param name="adminId"></param> private void AddBook(int adminId) { AdminView.AddBookPage(); var title = Console.ReadLine(); var author = Console.ReadLine(); var price = InputHelper.ParseInput(); var amount = InputHelper.ParseInput(); if (title != "" && author != "" && price != 0 && amount != 0) { WebbShopAPI api = new WebbShopAPI(); bool result = api.AddBook(adminId, title, author, price, amount); if (result) { MessageViews.DisplaySuccessMessage(); return; } } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows admin user to demote another admin user /// </summary> /// <param name="adminId"></param> private void DemoteUser(int adminId) { ViewAllUsers(adminId); MessageViews.DisplaySelectMessage(); MessageViews.DisplayReturnMessage(); var userId = InputHelper.ParseInput(); if (userId == 0) { return; } WebbShopAPI api = new WebbShopAPI(); bool result = api.Demote(adminId, userId); if (result) { MessageViews.DisplaySuccessMessage(); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows admin user to delete book category /// </summary> /// <param name="adminId"></param> private void DeleteCategory(int adminId) { new Book().ViewAllCategories(); MessageViews.DisplaySelectMessage(); MessageViews.DisplayReturnMessage(); var categoryId = InputHelper.ParseInput(); if (categoryId == 0) { return; } WebbShopAPI api = new WebbShopAPI(); var result = api.DeleteCategory(adminId, categoryId); if (result) { MessageViews.DisplaySuccessMessage(); return; } MessageViews.DisplayErrorMessage(); }
/// <summary> /// Allows admin user to delete book /// </summary> /// <param name="adminId"></param> private void DeleteBook(int adminId) { new Book().FindAllAvailableBooks(); MessageViews.DisplaySelectMessage(); MessageViews.DisplayReturnMessage(); var bookId = InputHelper.ParseInput(); if (bookId == 0) { return; } WebbShopAPI api = new WebbShopAPI(); bool result = api.DeleteBook(adminId, bookId); if (result) { MessageViews.DisplaySuccessMessage(); return; } MessageViews.DisplayErrorMessage(); }