Exemplo n.º 1
0
        public Result Execute(RefillBalanceInput input)
        {
            Result <MoneyToCharge> moneyToCharge = MoneyToCharge.Create(input.MoneyAmount);

            Result <Customer> customer = _customerRepository.Get(input.CustomerId).ToResult("Customer doesn't exist.");

            return(Result.Combine(moneyToCharge, customer)
                   .OnSuccess(() => customer.Value.AddBalance(moneyToCharge.Value.Value).ToResult("For increment the current balance the value at increment must be greater than 100"))
                   .OnSuccess(() => _paymentGateway.Charge(customer.Value.BillingInfo, moneyToCharge.Value.Value))
                   .OnSuccess(() => _uow.Commit().OnFailure(() => _paymentGateway.Rollback()))
                   .OnBoth(() => _log.Info("RefillBalanceCommand has been executed.")));
        }
        public string RefillBalance(int customerId, decimal moneyAmount)
        {
            Result <MoneyToCharge>      moneyToCharge = MoneyToCharge.Create(moneyAmount);
            Result <CustomerManagement> customer      = _database.GetById(customerId).ToResult("Customer is not found");

            return(Result.Combine(moneyToCharge, customer)
                   .OnSuccess(() => customer.value.AddBalance(moneyToCharge.value))
                   .OnSuccess(() => _paymentGateway.ChargePayment(customer.value.BillingInfo, moneyToCharge.value))
                   .OnSuccess(
                       () => _database.Save(customer.value)
                       .OnFailure(() => _paymentGateway.RollbackLastTransaction()))
                   .OnBoth(result => Log(result))
                   .OnBoth(result => result.isSuccues ? "OK" : result.Error));
        }
Exemplo n.º 3
0
 public void AddBalance(MoneyToCharge amount)
 {
     Balance += amount;
 }