private async Task PurchaseOrder() { WriteSection("Purchase"); while (true) { try { var product = _command.GetProduct(); await _mediator.Send(new SelectProduct(product)); while (true) { try { var coins = _command.GetCoins(); await _mediator.Send(new InsertCoins(coins)); break; } catch (NotSufficientAmountException ex) { _terminal.WriteLine($"{ex.Message}"); _terminal.WriteLine($"Remaining Amount: {ex.RemainingAmount}"); if (!_prompt.ReadBool(_insertRemainingAmountMessage, true)) { await CancelOrder(); return; } } catch (VendingMachineValiationException ex) { _terminal.WriteLine($"{ex.Message}"); } } if (!_prompt.ReadBool(_confirmPurchaseMessage, true)) { await CancelOrder(); break; } await _mediator.Send(new ProcessOrder(false)); break; } catch (NotSufficientChangeException ex) { _terminal.WriteLine(ex.Message); if (_prompt.ReadBool(_confirmPurchaseMessage, false)) { await CancelOrder(); break; } await _mediator.Send(new ProcessOrder(true)); break; } catch (ProductNotAvailableException ex) { _terminal.WriteLine(ex.Message); } catch (VendingMachineValiationException ex) { _terminal.WriteLine($"{ex.Message}"); } catch (Exception ex) { _terminal.WriteError(ex.Message); } } }