public Guid Add(EditPlayerBankAccountData model) { using (var scope = CustomTransactionScope.GetTransactionScope(IsolationLevel.RepeatableRead)) { var validationResult = new AddPlayerBankAccountValidator(_repository, _queries).Validate(model); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } var player = _repository.Players .Include(x => x.CurrentBankAccount) .Single(x => x.Id == model.PlayerId); var bank = _repository.Banks .Include(x => x.Brand) .Single(x => x.Id == model.Bank); var bankAccount = new PlayerBankAccount { Id = Guid.NewGuid(), Player = player, Status = BankAccountStatus.Pending, Bank = bank, Province = model.Province, City = model.City, Branch = model.Branch, SwiftCode = model.SwiftCode, Address = model.Address, AccountName = model.AccountName, AccountNumber = model.AccountNumber, Created = DateTimeOffset.Now.ToBrandOffset(bank.Brand.TimezoneId), CreatedBy = _actorInfoProvider.Actor.UserName }; if (player.CurrentBankAccount == null || player.CurrentBankAccount.Status != BankAccountStatus.Active) { if (player.CurrentBankAccount != null) { player.CurrentBankAccount.IsCurrent = false; } player.CurrentBankAccount = bankAccount; bankAccount.IsCurrent = true; } _repository.PlayerBankAccounts.Add(bankAccount); _repository.SaveChanges(); _eventBus.Publish(new PlayerBankAccountAdded { Id = bankAccount.Id, Name = bankAccount.AccountName, Number = bankAccount.AccountNumber, EventCreated = bankAccount.Created, }); scope.Complete(); return(bankAccount.Id); } }
public ValidationResult ValidateThatPlayerBankAccountCanBeAdded(EditPlayerBankAccountData data) { var validator = new AddPlayerBankAccountValidator(_repository, _queries); return(validator.Validate(data)); }