예제 #1
0
        public void Edit(EditPlayerBankAccountData model)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope(IsolationLevel.RepeatableRead))
            {
                var validationResult = new EditPlayerBankAccountValidator(_repository, _queries).Validate(model);

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

                var bank = _repository.Banks.Single(x => x.Id == model.Bank);

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

                var isModified =
                    bankAccount.Bank.Id != bank.Id ||
                    bankAccount.Province != model.Province ||
                    bankAccount.City != model.City ||
                    bankAccount.Branch != model.Branch ||
                    bankAccount.SwiftCode != model.SwiftCode ||
                    bankAccount.Address != model.Address ||
                    bankAccount.AccountName != model.AccountName ||
                    bankAccount.AccountNumber != model.AccountNumber;

                if (isModified)
                {
                    bankAccount.Status = BankAccountStatus.Pending;
                }

                bankAccount.Bank          = bank;
                bankAccount.Province      = model.Province;
                bankAccount.City          = model.City;
                bankAccount.Branch        = model.Branch;
                bankAccount.SwiftCode     = model.SwiftCode;
                bankAccount.Address       = model.Address;
                bankAccount.AccountName   = model.AccountName;
                bankAccount.AccountNumber = model.AccountNumber;
                bankAccount.Updated       = DateTimeOffset.Now.ToBrandOffset(bankAccount.Player.Brand.TimezoneId);
                bankAccount.UpdatedBy     = _actorInfoProvider.Actor.UserName;

                _repository.SaveChanges();
                _eventBus.Publish(new PlayerBankAccountEdited
                {
                    Id           = bankAccount.Id,
                    Name         = bankAccount.AccountName,
                    Number       = bankAccount.AccountNumber,
                    EventCreated = bankAccount.Updated.Value,
                });

                scope.Complete();
            }
        }
예제 #2
0
        public ValidationResult ValidateThatPlayerBankAccountCanBeEdited(EditPlayerBankAccountData data)
        {
            var validator = new EditPlayerBankAccountValidator(_repository, _queries);

            return(validator.Validate(data));
        }