Ejemplo n.º 1
0
 public User BuyCurrency(BuyCurrencyCommand command)
 {
     buyCurrencyValidator.ValidateCanBuyCurrency(command);
     ChargeCantorCosts(command);
     ChargeUserCosts(command);
     AddOrUpdateUserCurrencyAmount(command);
     return(command.User);
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 5
0
 private void EditCurrencyAmount(BuyCurrencyCommand command)
 {
     command.UserCurrency.Amount += command.Amount;
 }
Ejemplo n.º 6
0
 private void ChargeUserCosts(BuyCurrencyCommand command)
 {
     command.User.Money -= command.UserMoneyCosts;
 }
Ejemplo n.º 7
0
 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);
 }