public User BuyCurrency(BuyCurrencyCommand command) { buyCurrencyValidator.ValidateCanBuyCurrency(command); ChargeCantorCosts(command); ChargeUserCosts(command); AddOrUpdateUserCurrencyAmount(command); return(command.User); }
private void AddNewCurrency(BuyCurrencyCommand command) { if (command.User.Currencies == null) { command.User.Currencies = new List <WalletCurrency>(); } var userCurrency = walletCurrencyFactory.Create(command.Currency, command.User, command.Amount); command.User.Currencies.Add(userCurrency); }
private void AddOrUpdateUserCurrencyAmount(BuyCurrencyCommand command) { if (command.UserCurrency == null) { AddNewCurrency(command); } else { EditCurrencyAmount(command); } }
public bool ValidateCanBuyCurrency(BuyCurrencyCommand command) { transactionValidator.ValidateTransaction(command); if (HasUserNotEnoughFunds(command)) { throw new BuyCurrencyException("User doesn't have enough funds"); } if (HasCantorNotEnoughCurrencyAmount(command)) { throw new BuyCurrencyException("Cantor doesn't have enough currency amount"); } return(true); }
private void EditCurrencyAmount(BuyCurrencyCommand command) { command.UserCurrency.Amount += command.Amount; }
private void ChargeUserCosts(BuyCurrencyCommand command) { command.User.Money -= command.UserMoneyCosts; }
private void ChargeCantorCosts(BuyCurrencyCommand command) { command.CantorCurrency.Amount -= command.Amount; }
private bool HasUserNotEnoughFunds(BuyCurrencyCommand command) { return(command.User.Money < command.UserMoneyCosts); }
private bool HasCantorNotEnoughCurrencyAmount(BuyCurrencyCommand command) { return(command.CantorCurrency.Amount < command.Amount); }