public void BuyStuff() { IDatabase database = CreateDatabase(); IActionHandler actionHandler = new ActionHandler(); IShoppingService shoppingService = new ShoppingService(database); IOrderProcessor orderProcessor = new OrderProcessor(database, actionHandler); User user = shoppingService.SignIn("*****@*****.**", "secret"); Cart cart = shoppingService.GetCart("*****@*****.**"); Product ball = shoppingService.GetProduct("Ball"); cart.AddProduct(ball); cart.AddProduct(ball); cart.AddProduct(shoppingService.GetProduct("Monitor")); Result <Order> completedOrder = orderProcessor.CompleteOrder(cart); if (completedOrder.IsSuccessful) { Console.WriteLine($"Order was completed. You've spent {completedOrder.Value.TotalPrice} PLN."); return; } Console.WriteLine($"There was an error while completing an order.\n" + $"{completedOrder.ErrorMessage}"); }
public void BuyStuff() { IDatabase database = CreateDatabase(); IShoppingService shoppingService = new ShoppingService(database); IOrderProcessor orderProcessor = new OrderProcessor(database); IActionHandler actionHandler = new ActionHandler(); User user = shoppingService.SignIn("*****@*****.**", "secret"); Cart cart = shoppingService.GetCart("*****@*****.**"); Product ball = shoppingService.GetProduct("Ball"); cart.AddProduct(ball); cart.AddProduct(ball); cart.AddProduct(shoppingService.GetProduct("Monitor")); var completedOrder = actionHandler .Handle(() => orderProcessor.CompleteOrder(cart)); var order = completedOrder.Item; if (completedOrder.IsValid) { Console.WriteLine($"Order was completed. You've spent {order.TotalPrice} PLN."); return; } Console.WriteLine(completedOrder.ErrorMessage); }