Ejemplo n.º 1
0
        public void SetCurrent(PlayerBankAccountId playerBankAccountId)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var setCurrentPlayerBankAccountCommand = new SetCurrentPlayerBankAccountData
                {
                    PlayerBankAccountId = playerBankAccountId
                };

                var validationResult = new SetCurrentPlayerBankAccountValidator(_repository).Validate(setCurrentPlayerBankAccountCommand);

                if (!validationResult.IsValid)
                {
                    throw new RegoValidationException(validationResult);
                }

                var bankAccount = _repository.PlayerBankAccounts
                                  .Include(x => x.Player.CurrentBankAccount)
                                  .Include(x => x.Player.Brand)
                                  .Include(x => x.Bank)
                                  .Single(x => x.Id == setCurrentPlayerBankAccountCommand.PlayerBankAccountId);

                bankAccount.Player.CurrentBankAccount.IsCurrent = false;
                bankAccount.Player.CurrentBankAccount           = bankAccount;
                bankAccount.IsCurrent = true;

                _repository.SaveChanges();

                _eventBus.Publish(new PlayerBankAccountCurrentSet(
                                      bankAccount.Player.Id,
                                      bankAccount.Id,
                                      bankAccount.AccountNumber)
                {
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(bankAccount.Player.Brand.TimezoneId),
                });

                scope.Complete();
            }
        }
Ejemplo n.º 2
0
        public ValidationResult ValidateThatPlayerBankAccountCanBeSet(SetCurrentPlayerBankAccountData data)
        {
            var validator = new SetCurrentPlayerBankAccountValidator(_repository);

            return(validator.Validate(data));
        }