/// <summary> /// Checks whether the session is active for the userid in the parameter /// Calls the Ping() method from WebbShopAPI class. /// </summary> /// <param name="userId"></param> /// <param name="errorMsg"></param> /// <returns>True if successfull, else false</returns> internal bool IsSessionActive(int userId, out string errorMsg) { errorMsg = ""; string answer = webAPI.Ping(userId); if (answer == "Pong") { return(true); } else { errorMsg = "Session Timed out"; return(false); } }
/// <summary> /// Runs the home functionality page /// </summary> public void Run() { Seeder.Seed(); bool keepGoing = true; while (keepGoing) { HomeView.MainMeny(); var input = InputHelper.ParseInput(); if (userId > 0) { WebbShopAPI api = new WebbShopAPI(); api.Ping(userId); } switch (input) { case 1: userId = new Login().Run(); break; case 2: new User().RegisterAccount(); break; case 3: new Book().Run(); break; case 4: new Purchase().Run(userId); break; case 5: userId = new Admin().Run(); break; case 6: new Logout().Run(userId); keepGoing = false; break; default: MessageViews.DisplayNonAvailableMessage(); break; } } }
/// <summary> /// Runs a test-scenario /// </summary> public static void Run() { var api = new WebbShopAPI(); Console.Write("Logged in as: "); int userId = api.Login("TestCustomer", "Codic2021"); Console.WriteLine(userId); //--------------------------------------------------- Console.WriteLine("Searching all categories: "); var listOfCategories = api.GetCategories(); if (listOfCategories.Count > 0) { foreach (var category in listOfCategories) { Console.WriteLine(category.Genere); } } //--------------------------------------------------- Console.WriteLine("Searching all categories with \"or\"-keyword: "); listOfCategories = api.GetCategories("or"); if (listOfCategories.Count > 0) { foreach (var category in listOfCategories) { Console.WriteLine(category.Genere); } } //--------------------------------------------------- Console.WriteLine("Searching for all books with category \"Horror\": "); var listOfBooks = api.GetCategories(2); if (listOfBooks.Count > 0) { foreach (var book in listOfBooks) { Console.WriteLine(book.Title); } } var respons = api.Ping(userId); if (respons.Length > 0) { Console.WriteLine(respons); } //--------------------------------------------------- Console.WriteLine("Searching for all available books with category \"Horror\": "); var listOfAvailableBooks = api.GetAvailableBooks(2); foreach (var book in listOfAvailableBooks) { Console.WriteLine($"{book.Title}, Amount: {book.Amount}"); } //--------------------------------------------------- Console.WriteLine("Information around all books with genere \"Horror\""); var description = api.GetBook(4); Console.WriteLine(description); //--------------------------------------------------- Console.WriteLine("Searching for books matching search word \"shi\""); listOfBooks = api.GetBooks("shi"); foreach (var book in listOfBooks) { Console.WriteLine(book.Title); } respons = api.Ping(userId); if (respons.Length > 0) { Console.WriteLine(respons); } //--------------------------------------------------- Console.WriteLine("Searching for books matching Author \"Stephen King\""); listOfBooks = api.GetAuthor("Stephen King"); foreach (var book in listOfBooks) { Console.WriteLine(book.Title); } //--------------------------------------------------- Console.WriteLine("Selected book to purchase: \"Doctor Sleep\""); var succeed = api.BuyBook(userId, 2); if (succeed) { Console.WriteLine("Purchase made"); } //--------------------------------------------------- api.Logout(userId); }