Beispiel #1
0
        public void Reject(RejectOnlineDepositRequest request)
        {
            var onlineDeposit = _repository.OnlineDeposits.First(x => x.Id == request.Id);

            if (onlineDeposit == null)
            {
                throw new RegoException(DepositErrors.NotFound.ToString());
            }

            var onlineDepositEntity = new Entities.OnlineDeposit(onlineDeposit);

            var now = _paymentQueries.GetBrandDateTimeOffset(onlineDeposit.BrandId);

            var rejectedEvent = onlineDepositEntity.Reject(_actorInfoProvider.Actor.UserName, request.Remarks, now);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _repository.SaveChanges();

                _eventBus.Publish(rejectedEvent);

                scope.Complete();
            }
        }
Beispiel #2
0
        public void Handle(TransferFundCreated @event)
        {
            if (@event.Type == TransferFundType.FundOut || @event.Status == TransferFundStatus.Rejected)
            {
                return;
            }

            var bonusCommands    = _container.Resolve <BonusCommands>();
            var bonusQueries     = _container.Resolve <BonusQueries>();
            var redemptionParams = new RedemptionParams {
                TransferAmount = @event.Amount, TransferWalletTemplateId = @event.DestinationWalletStructureId
            };

            var repository = _container.Resolve <IBonusRepository>();

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                bonusQueries
                .GetQualifiedAutomaticBonusIds(@event.PlayerId, BonusType.FundIn, redemptionParams)
                .ForEach(bonusId => bonusCommands.ActivateFundInBonus(@event.PlayerId, bonusId, redemptionParams));

                var wallet = repository.GetLockedWallet(@event.PlayerId);

                if (@event.Amount > 0)
                {
                    wallet.TransferFundCredit(@event.Amount);
                }
                else
                {
                    wallet.TransferFundDebit(@event.Amount);
                }

                repository.SaveChanges();
                scope.Complete();
            }
        }
Beispiel #3
0
        public void DeactivateBrand(DeactivateBrandRequest request)
        {
            var brand = _repository.Brands.SingleOrDefault(x => x.Id == request.BrandId);

            if (brand != null)
            {
                brand.Remarks = request.Remarks;
            }

            var deactivateBrandData = new DeactivateBrandValidationData {
                Brand = brand
            };

            var validationResult = new DeactivateBrandValidator().Validate(deactivateBrandData);

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

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                brand.Status      = BrandStatus.Deactivated;
                brand.UpdatedBy   = brand.DeactivatedBy = _actorInfoProvider.Actor.UserName;
                brand.DateUpdated = brand.DateDeactivated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId);

                _repository.SaveChanges();

                _eventBus.Publish(new BrandDeactivated
                {
                    Id           = request.BrandId,
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });
                scope.Complete();
            }
        }
Beispiel #4
0
        public Guid AddBankAccountType(BankAccountType bankAccountType)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = new AddBankAccountTypeValidator(_repository).Validate(bankAccountType);

                if (!validationResult.IsValid)
                {
                    throw new RegoException(validationResult.Errors.First().ErrorMessage);
                }

                if (bankAccountType.Id.Equals(Guid.Empty))
                {
                    bankAccountType.Id = Guid.NewGuid();
                }

                var bankAccountTypeEntity = new AFT.RegoV2.Core.Payment.Data.BankAccountType
                {
                    Id   = bankAccountType.Id,
                    Name = bankAccountType.Name
                };

                _repository.BankAccountTypes.Add(bankAccountTypeEntity);
                _repository.SaveChanges();

                _eventBus.Publish(new BankAccountTypeAdded
                {
                    Id   = bankAccountTypeEntity.Id,
                    Name = bankAccountTypeEntity.Name,
                });

                scope.Complete();

                return(bankAccountType.Id);
            }
        }
Beispiel #5
0
        private WalletOperationResult PerformFundOperation(Guid playerId, decimal amount, string transactionNumber, bool isFundIn)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var wallet = _repository.GetWalletWithUPDLock(playerId);

                var transaction = wallet.Data.Transactions.FirstOrDefault(x => x.TransactionNumber == transactionNumber);
                if (transaction != null)
                {
                    return(GetOperationResult(wallet, transaction, true));
                }

                transaction = isFundIn ? wallet.FundIn(amount, transactionNumber) : wallet.FundOut(amount, transactionNumber);

                _repository.SaveChanges();

                // PublishMessage has to know the exact event type!
                wallet.Events.ForEach(@event => _serviceBus.PublishExternalMessage(@event));

                scope.Complete();

                return(GetOperationResult(wallet, transaction, false));
            }
        }
Beispiel #6
0
        public BrandIpRegulation CreateIpRegulation(AddBrandIpRegulationData data)
        {
            var regulation = Mapper.DynamicMap <BrandIpRegulation>(data);
            var brand      = Repository.Brands.Single(x => x.Id == data.BrandId);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                regulation.Id          = Guid.NewGuid();
                regulation.CreatedBy   = Repository.Admins.SingleOrDefault(u => u.Id == ActorInfoProvider.Actor.Id);
                regulation.CreatedDate = DateTimeOffset.Now.ToBrandOffset(brand.TimeZoneId);

                Repository.BrandIpRegulations.Add(regulation);
                Repository.SaveChanges();

                _eventBus.Publish(new BrandIpRegulationCreated(regulation)
                {
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimeZoneId),
                });

                scope.Complete();
            }

            return(regulation);
        }
Beispiel #7
0
        public void AssignBrandCulture(AssignBrandCultureRequest assignBrandCultureData)
        {
            var validationResult = new AssignBrandCultureValidator(_repository).Validate(assignBrandCultureData);

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

            var brand = _repository.Brands
                        .Include(x => x.BrandCultures)
                        .Single(x => x.Id == assignBrandCultureData.Brand);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var oldCultures = brand.BrandCultures
                                  .Where(x => !assignBrandCultureData.Cultures.Contains(x.CultureCode))
                                  .ToArray();

                foreach (var oldCulture in oldCultures)
                {
                    brand.BrandCultures.Remove(oldCulture);
                }

                var newCultures = assignBrandCultureData.Cultures
                                  .Where(x => brand.BrandCultures.All(y => y.CultureCode != x))
                                  .ToArray();

                foreach (var culture in newCultures)
                {
                    var cultureToAdd = _repository.Cultures.Single(x => x.Code == culture);

                    brand.BrandCultures.Add(new BrandCulture
                    {
                        BrandId     = brand.Id,
                        Brand       = brand,
                        CultureCode = cultureToAdd.Code,
                        Culture     = cultureToAdd,
                        DateAdded   = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                        AddedBy     = _actorInfoProvider.Actor.UserName
                    });
                }

                brand.DefaultCulture = assignBrandCultureData.DefaultCulture;
                brand.DateUpdated    = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId);
                brand.UpdatedBy      = _actorInfoProvider.Actor.UserName;

                _repository.SaveChanges();

                _eventBus.Publish(new BrandLanguagesAssigned(
                                      brand.Id,
                                      brand.Name,
                                      brand.BrandCultures.Select(x => x.Culture),
                                      brand.DefaultCulture)
                {
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });

                scope.Complete();
            }
        }
        public AutoVerificationCheckConfiguration Create(AVCConfigurationDTO data)
        {
            ValidateAvcEntity(data, AvcConfigurationDtoQueriesEnum.Create);

            var entity = new AutoVerificationCheckConfiguration
            {
                Id = data.Id,
                HasFraudRiskLevel = data.HasFraudRiskLevel,
                BrandId           = data.Brand,
                Brand             = _fraudRepository.Brands.First(x => x.Id == data.Brand),
                Currency          = data.Currency,
                DateCreated       = DateTimeOffset.UtcNow,

                HasWinLoss      = data.HasWinLoss,
                WinLossAmount   = data.WinLossAmount,
                WinLossOperator = data.WinLossOperator,

                HasCompleteDocuments = data.HasCompleteDocuments,

                HasWithdrawalExemption = data.HasWithdrawalExemption,

                HasTotalDepositAmount      = data.HasTotalDepositAmount,
                TotalDepositAmount         = data.TotalDepositAmount,
                TotalDepositAmountOperator = data.TotalDepositAmountOperator,

                HasDepositCount           = data.HasDepositCount,
                TotalDepositCountAmount   = data.TotalDepositCountAmount,
                TotalDepositCountOperator = data.TotalDepositCountOperator,

                HasAccountAge      = data.HasAccountAge,
                AccountAge         = data.AccountAge,
                AccountAgeOperator = data.AccountAgeOperator,

                HasWithdrawalCount           = data.HasWithdrawalCount,
                TotalWithdrawalCountAmount   = data.TotalWithdrawalCountAmount,
                TotalWithdrawalCountOperator = data.TotalWithdrawalCountOperator,

                HasNoRecentBonus = data.HasNoRecentBonus,
                CreatedBy        = _actorInfoProvider.Actor.Id,

                HasPaymentLevel = data.HasPaymentLevel,
                Status          = data.Status
            };

            //ToDo: Add validation here
            if (entity.Id == Guid.Empty)
            {
                entity.Id = Guid.NewGuid();
            }

            if (data.HasFraudRiskLevel)
            {
                //Let's add all risk levels.
                var brand = _fraudRepository.Brands
                            .Single(x => x.Id == data.Brand);

                _fraudRepository.RiskLevels
                .Where(x => x.BrandId == brand.Id)
                .ForEach(x => entity.AllowedRiskLevels.Add(x));

                //Let's remove all ignored via UI
                foreach (var riskLevelId in data.RiskLevels)
                {
                    var riskLevel = entity.AllowedRiskLevels.FirstOrDefault(x => x.Id == riskLevelId);
                    if (riskLevel != null)
                    {
                        entity.AllowedRiskLevels.Remove(riskLevel);
                    }
                }
            }

            if (data.HasPaymentLevel)
            {
                entity.PaymentLevels.Clear();

                //Let's add all payment levels.
                var currentlySelectedPaymentLevels = _fraudRepository
                                                     .PaymentLevels
                                                     .Where(x => data.PaymentLevels.Contains(x.Id));

                currentlySelectedPaymentLevels.ForEach(x => entity.PaymentLevels.Add(x));
            }

            if (data.HasWinnings)
            {
                entity.HasWinnings = true;
                foreach (var winningRule in data.WinningRules)
                {
                    var rule = CreateWinningRuleEntity(winningRule, entity);

                    if (winningRule.Period == PeriodEnum.CustomDate)
                    {
                        rule.StartDate = winningRule.StartDate;
                        rule.EndDate   = winningRule.EndDate;
                    }

                    entity.WinningRules.Add(rule);
                }
            }

            entity.VipLevels.Clear();
            data.VipLevels
            .ForEach(id =>
            {
                var vipLevel = _fraudRepository.VipLevels
                               .Single(x => x.Id == id);

                entity.VipLevels.Add(vipLevel);
            });

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _fraudRepository.AutoVerificationCheckConfigurations.Add(entity);
                _fraudRepository.SaveChanges();
                scope.Complete();
            }

            _eventBus.Publish(new AutoVerificationCheckCreated()
            {
                CreatedBy   = _actorInfoProvider.Actor.UserName,
                DateCreated = DateTime.UtcNow
            });

            return(entity);
        }
        public void Update(AVCConfigurationDTO data)
        {
            this.ValidateAvcEntity(data, AvcConfigurationDtoQueriesEnum.Update);

            var entity = _fraudRepository.AutoVerificationCheckConfigurations
                         .Include(o => o.VipLevels)
                         .Single(x => x.Id == data.Id);

            entity.HasFraudRiskLevel = data.HasFraudRiskLevel;
            entity.BrandId           = data.Brand;
            entity.Brand             = _fraudRepository.Brands.First(x => x.Id == data.Brand);
            entity.Currency          = data.Currency;

            entity.VipLevels.Clear();
            data.VipLevels
            .ForEach(id =>
            {
                var vipLevel = _fraudRepository.VipLevels
                               .Single(x => x.Id == id);

                entity.VipLevels.Add(vipLevel);
            });

            entity.HasPaymentLevel = data.HasPaymentLevel;

            entity.HasWinnings = data.HasWinnings;
            UpdateWinningRules(entity, data);
            // entity.WinningRules = data.WinningRules.Select(Mapper.Map<WinningRule>) as ICollection<WinningRule>;

            entity.HasCompleteDocuments = data.HasCompleteDocuments;

            entity.HasWinLoss      = data.HasWinLoss;
            entity.WinLossAmount   = data.WinLossAmount;
            entity.WinLossOperator = data.WinLossOperator;

            entity.HasWithdrawalCount           = data.HasWithdrawalCount;
            entity.TotalWithdrawalCountAmount   = data.TotalWithdrawalCountAmount;
            entity.TotalWithdrawalCountOperator = data.TotalWithdrawalCountOperator;

            entity.HasAccountAge      = data.HasAccountAge;
            entity.AccountAge         = data.AccountAge;
            entity.AccountAgeOperator = data.AccountAgeOperator;

            entity.HasTotalDepositAmount      = data.HasTotalDepositAmount;
            entity.TotalDepositAmount         = data.TotalDepositAmount;
            entity.TotalDepositAmountOperator = data.TotalDepositAmountOperator;

            entity.HasDepositCount           = data.HasDepositCount;
            entity.TotalDepositCountAmount   = data.TotalDepositCountAmount;
            entity.TotalDepositCountOperator = data.TotalDepositCountOperator;

            entity.HasNoRecentBonus = data.HasNoRecentBonus;

            entity.HasWithdrawalExemption = data.HasWithdrawalExemption;

            if (data.HasFraudRiskLevel)
            {
                entity.AllowedRiskLevels.Clear();

                //Let's add all risk levels.
                _fraudRepository
                .RiskLevels
                .Include(x => x.Brand)
                .Where(x => x.Brand != null)
                .Where(x => x.Brand.Id == data.Brand)
                .ForEach(x => entity.AllowedRiskLevels.Add(x));

                //Let's remove all ignored via UI
                foreach (var riskLevelId in data.RiskLevels)
                {
                    var riskLevel = entity.AllowedRiskLevels.FirstOrDefault(x => x.Id == riskLevelId);
                    if (riskLevel != null)
                    {
                        entity.AllowedRiskLevels.Remove(riskLevel);
                    }
                }
            }

            if (data.HasPaymentLevel)
            {
                entity.PaymentLevels.Clear();

                //Let's add all payment levels.
                var currentlySelectedPaymentLevels = _fraudRepository
                                                     .PaymentLevels
                                                     .Where(x => data.PaymentLevels.Contains(x.Id));

                currentlySelectedPaymentLevels.ForEach(x => entity.PaymentLevels.Add(x));
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _fraudRepository.AutoVerificationCheckConfigurations.AddOrUpdate(entity);
                _fraudRepository.SaveChanges();
                scope.Complete();
            }

            _eventBus.Publish(new AutoVerificationCheckUpdated()
            {
                UpdatedBy   = _actorInfoProvider.Actor.UserName,
                DateUpdated = DateTime.UtcNow
            });
        }
        public void Update(RiskProfileCheckDTO data)
        {
            var entity = _fraudRepository.RiskProfileConfigurations
                         .Include(o => o.AllowedPaymentMethods)
                         .Include(o => o.AllowedBonuses)
                         .Include(o => o.AllowedRiskLevels)
                         .Include(o => o.VipLevels)
                         .Single(o => o.Id == data.Id);

            ValidateData(data, RiskAction.Update);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                CopyFromModel(data, entity);

                entity.AllowedRiskLevels.Clear();
                if (data.HasFraudRiskLevel)
                {
                    foreach (var riskLevelId in data.RiskLevels)
                    {
                        var riskLevel = _fraudRepository.RiskLevels
                                        .Single(x => x.Id == riskLevelId);

                        entity.AllowedRiskLevels.Add(riskLevel);
                    }
                }

                entity.AllowedPaymentMethods.Clear();
                if (data.HasPaymentMethodCheck)
                {
                    foreach (var paymentMethodId in data.PaymentMethods)
                    {
                        var method = _fraudRepository.PaymentMethods
                                     .Single(o => o.Id == paymentMethodId);

                        entity.AllowedPaymentMethods.Add(method);
                    }
                }

                entity.AllowedBonuses.Clear();
                if (data.HasBonusCheck)
                {
                    foreach (var bonusId in data.Bonuses)
                    {
                        var bonus = _fraudRepository.Bonuses
                                    .Single(o => o.Id == bonusId);

                        entity.AllowedBonuses.Add(bonus);
                    }
                }

                _fraudRepository.SaveChanges();
                scope.Complete();
            }

            _eventBus.Publish(new RiskProfileCheckConfigUpdated
            {
                Id          = entity.Id,
                UpdatedBy   = _actorInfoProvider.Actor.UserName,
                DateUpdated = DateTimeOffset.Now
            });
        }
Beispiel #11
0
        public UpdateRecipientsResponse UpdateRecipients(UpdateRecipientsRequest request)
        {
            var validationResult = _massMessageQueries.GetValidationResult(request);

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

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                if (!request.Id.HasValue)
                {
                    DeleteUnsentMassMessages();
                }

                MassMessage massMessage;

                if (request.Id.HasValue)
                {
                    massMessage = _messagingRepository.MassMessages
                                  .Include(x => x.Recipients.Select(y => y.Language))
                                  .Single(x => x.Id == request.Id);
                }
                else
                {
                    massMessage = new MassMessage
                    {
                        Id      = Guid.NewGuid(),
                        AdminId = _actorInfoProvider.Actor.Id
                    };

                    _messagingRepository.MassMessages.Add(massMessage);
                }

                massMessage.IpAddress = request.IpAddress;

                if (request.UpdateRecipientsType == UpdateRecipientsType.SelectSingle)
                {
                    massMessage.Recipients.Add(_messagingRepository.Players
                                               .Include(x => x.Language)
                                               .Single(x => x.Id == request.PlayerId));
                }
                else if (request.UpdateRecipientsType == UpdateRecipientsType.UnselectSingle)
                {
                    massMessage.Recipients.Remove(massMessage.Recipients.Single(x => x.Id == request.PlayerId));
                }
                else if (request.UpdateRecipientsType == UpdateRecipientsType.RecipientsListUnselectAll)
                {
                    massMessage.Recipients.Clear();
                }
                else
                {
                    var playerIds = _massMessageQueries.CreateMassMessagePlayerQuery(request.SearchPlayersRequest)
                                    .Select(x => x.Id);

                    if (request.UpdateRecipientsType == UpdateRecipientsType.SearchResultSelectAll)
                    {
                        var players = _messagingRepository.Players
                                      .Include(x => x.Language)
                                      .Where(x => playerIds.Contains(x.Id));

                        foreach (var player in players)
                        {
                            massMessage.Recipients.Add(player);
                        }
                    }
                    else
                    {
                        var recipients = massMessage.Recipients.Where(x => playerIds.Contains(x.Id)).ToArray();

                        foreach (var recipient in recipients)
                        {
                            massMessage.Recipients.Remove(recipient);
                        }
                    }
                }

                _messagingRepository.SaveChanges();

                scope.Complete();

                IEnumerable <Interface.Data.Language> languages = null;

                if (massMessage.Recipients.Any())
                {
                    var languageEntities = massMessage.Recipients.GroupBy(x => x.LanguageCode).Select(x => x.First().Language);
                    languages = Mapper.Map <List <Interface.Data.Language> >(languageEntities);
                }

                return(new UpdateRecipientsResponse
                {
                    Id = massMessage.Id,
                    HasRecipients = massMessage.Recipients.Any(),
                    Languages = languages
                });
            }
        }
Beispiel #12
0
        public void EditVipLevel(VipLevelViewModel model)
        {
            var validationResult = ValidateThatVipLevelCanBeEdited(model);

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

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var existingVipLevel = _repository
                                       .VipLevels
                                       .Include(x => x.VipLevelGameProviderBetLimits)
                                       .Single(x => x.Id == model.Id);

                //update viplevel
                var brand = _repository.Brands.Single(x => x.Id == model.Brand);
                existingVipLevel.Brand         = brand;
                existingVipLevel.Code          = model.Code;
                existingVipLevel.Name          = model.Name;
                existingVipLevel.Rank          = model.Rank;
                existingVipLevel.Description   = model.Description;
                existingVipLevel.ColorCode     = model.Color;
                existingVipLevel.UpdatedBy     = _actorInfoProvider.Actor.UserName;
                existingVipLevel.DateUpdated   = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId);
                existingVipLevel.UpdatedRemark = model.Remark;
                //remove removed limits
                var removedLimits = existingVipLevel
                                    .VipLevelGameProviderBetLimits
                                    .Where(x => model.Limits.All(lvm => lvm.Id != x.Id))
                                    .ToArray();

                removedLimits.ForEach(x =>
                {
                    existingVipLevel.VipLevelGameProviderBetLimits.Remove(x);
                    _repository.VipLevelLimits.Remove(x);
                });

                //updating viplimits
                foreach (var limitViewModel in model.Limits)
                {
                    var limit = existingVipLevel.
                                VipLevelGameProviderBetLimits
                                .SingleOrDefault(x => x.Id == limitViewModel.Id);


                    if (limit == null)
                    {
                        limit = new VipLevelGameProviderBetLimit()
                        {
                            Id             = Guid.NewGuid(),
                            VipLevel       = existingVipLevel,
                            GameProviderId = limitViewModel.GameProviderId.Value,
                            Currency       = _repository.Currencies.Single(y => y.Code == limitViewModel.CurrencyCode),
                            BetLimitId     = limitViewModel.BetLimitId.Value
                        };
                        existingVipLevel.VipLevelGameProviderBetLimits.Add(limit);
                    }
                    else
                    {
                        limit.VipLevel       = existingVipLevel;
                        limit.GameProviderId = limitViewModel.GameProviderId.Value;
                        limit.Currency       = _repository.Currencies.Single(y => y.Code == limitViewModel.CurrencyCode);
                        limit.BetLimitId     = limitViewModel.BetLimitId.Value;
                    }
                }

                //save and publish
                _repository.SaveChanges();
                _eventBus.Publish(new VipLevelUpdated
                {
                    Id          = existingVipLevel.Id,
                    BrandId     = existingVipLevel.Brand.Id,
                    Code        = existingVipLevel.Code,
                    Name        = existingVipLevel.Name,
                    Rank        = existingVipLevel.Rank,
                    Description = existingVipLevel.Description,
                    ColorCode   = existingVipLevel.ColorCode,
                    Remark      = model.Remark,

                    VipLevelLimits = existingVipLevel.VipLevelGameProviderBetLimits.Select(x => new VipLevelLimitData
                    {
                        Id             = x.Id,
                        VipLevelId     = existingVipLevel.Id,
                        CurrencyCode   = x.Currency.Code,
                        GameProviderId = x.GameProviderId,
                        BetLimitId     = x.BetLimitId
                    }).ToArray(),
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });

                scope.Complete();
            }
        }
Beispiel #13
0
        public async Task <string> AddFund(TransferFundRequest request)
        {
            var validationResult = await _validationService.Validate(request);

            var transferFund      = new TransferFund();
            var transactionNumber = GenerateTransactionNumber();

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var requestWalletId       = new Guid(request.WalletId);
                var requestWalletTemplate = _brandQueries.GetWalletTemplate(requestWalletId);
                var mainWalletTemplate    = _brandQueries.GetWalletTemplates(requestWalletTemplate.Brand.Id).Single(wt => wt.IsMain);
                var timezoneId            = requestWalletTemplate.Brand.TimezoneId;

                _repository.TransferFunds.Add(transferFund);
                transferFund.Id                = Guid.NewGuid();
                transferFund.TransferType      = request.TransferType;
                transferFund.TransactionNumber = transactionNumber;
                transferFund.Amount            = request.Amount;
                transferFund.WalletId          = request.WalletId;
                transferFund.CreatedBy         = request.PlayerId.ToString();
                transferFund.Created           = DateTimeOffset.Now.ToBrandOffset(timezoneId);
                transferFund.Remarks           = transferFund.Remarks = !validationResult.IsValid ? validationResult.ErrorMessage : string.Empty;
                transferFund.Status            = validationResult.IsValid ? TransferFundStatus.Approved : TransferFundStatus.Rejected;
                transferFund.BonusCode         = request.BonusCode;

                if (validationResult.IsValid)
                {
                    var sourceWalletId = request.TransferType == TransferFundType.FundIn
                        ? mainWalletTemplate.Id
                        : requestWalletId;
                    var destinationWalletId = request.TransferType == TransferFundType.FundIn
                        ? requestWalletId
                        : mainWalletTemplate.Id;

                    //_walletCommands.TransferFunds(request.PlayerId, sourceWalletId, destinationWalletId, request.Amount, transactionNumber);
                    if (request.BonusId.HasValue || string.IsNullOrWhiteSpace(request.BonusCode) == false && transferFund.Status == TransferFundStatus.Approved)
                    {
                        await _bonusApiProxy.ApplyForBonusAsync(new FundInBonusApplication
                        {
                            PlayerId  = request.PlayerId,
                            BonusId   = request.BonusId,
                            BonusCode = request.BonusCode,
                            Amount    = request.Amount,
                            DestinationWalletTemplateId = destinationWalletId
                        });
                    }

                    transferFund.DestinationWalletId = destinationWalletId;
                }

                _eventBus.Publish(new TransferFundCreated
                {
                    PlayerId                     = new Guid(transferFund.CreatedBy),
                    TransactionNumber            = transferFund.TransactionNumber,
                    Amount                       = transferFund.Amount,
                    Remarks                      = transferFund.Remarks,
                    BonusCode                    = transferFund.BonusCode,
                    DestinationWalletStructureId = transferFund.DestinationWalletId,
                    Type        = transferFund.TransferType,
                    Status      = transferFund.Status,
                    Description = string.Format("Transaction #{0}", transferFund.TransactionNumber)
                });
                _repository.SaveChanges();
                scope.Complete();
            }

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

            return(transactionNumber);
        }
Beispiel #14
0
        public void SaveChanges(
            EditBankAccountData bankAccountData,
            byte[] idFrontImage,
            byte[] idBackImage,
            byte[] atmCardImage
            )
        {
            //Server Validation

            var frontImageId   = SaveFile(bankAccountData.IdFrontImage, idFrontImage, bankAccountData.Id);
            var backImageId    = SaveFile(bankAccountData.IdBackImage, idBackImage, bankAccountData.Id);
            var atmCardImageId = SaveFile(bankAccountData.AtmCardImage, atmCardImage, bankAccountData.Id);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var bankAccount = _repository.BankAccounts
                                  .Include(x => x.Bank.Brand)
                                  .Single(x => x.Id == bankAccountData.Id);

                bankAccount.Bank          = _repository.Banks.Single(x => x.Id == bankAccountData.Bank);
                bankAccount.CurrencyCode  = bankAccountData.Currency;
                bankAccount.AccountId     = bankAccountData.AccountId;
                bankAccount.AccountName   = bankAccountData.AccountName;
                bankAccount.AccountNumber = bankAccountData.AccountNumber;
                //bankAccount.AccountType = bankAccountData.AccountType;
                bankAccount.AccountType     = _repository.BankAccountTypes.Single(x => x.Id == bankAccountData.AccountType);
                bankAccount.Province        = bankAccountData.Province;
                bankAccount.Branch          = bankAccountData.Branch;
                bankAccount.Remarks         = bankAccountData.Remarks;
                bankAccount.SupplierName    = bankAccountData.SupplierName;
                bankAccount.ContactNumber   = bankAccountData.ContactNumber;
                bankAccount.USBCode         = bankAccountData.USBCode;
                bankAccount.PurchasedDate   = DateTime.Parse(bankAccountData.PurchasedDate);
                bankAccount.UtilizationDate = DateTime.Parse(bankAccountData.UtilizationDate);
                bankAccount.ExpirationDate  = DateTime.Parse(bankAccountData.ExpirationDate);
                //bankAccount.IdFrontImage = frontImageId;
                //bankAccount.IdBackImage = backImageId;
                //bankAccount.ATMCardImage = atmCardImageId;
                bankAccount.Updated   = DateTimeOffset.Now.ToBrandOffset(bankAccount.Bank.Brand.TimezoneId);
                bankAccount.UpdatedBy = _actorInfoProvider.Actor.UserName;

                if (frontImageId != null)
                {
                    bankAccount.IdFrontImage = frontImageId;
                }
                if (backImageId != null)
                {
                    bankAccount.IdBackImage = backImageId;
                }
                if (atmCardImageId != null)
                {
                    bankAccount.ATMCardImage = atmCardImageId;
                }

                _repository.SaveChanges();

                var bankAccountChanged = new BankAccountEdited
                {
                    Id                = bankAccount.Id,
                    AccountId         = bankAccount.AccountId,
                    Name              = bankAccount.AccountName,
                    Number            = bankAccount.AccountNumber,
                    BankId            = bankAccount.Bank.Id,
                    UpdatedBy         = bankAccount.UpdatedBy,
                    UpdatedDate       = bankAccount.Updated.Value,
                    BankAccountStatus = bankAccount.Status,
                    EventCreated      = bankAccount.Updated.Value,
                    Remarks           = bankAccount.Remarks
                };

                _eventBus.Publish(bankAccountChanged);

                scope.Complete();
            }
        }
Beispiel #15
0
        public Guid AddWithFiles(AddBankAccountData data, byte[] idFrontImage, byte[] idBackImage,
                                 byte[] atmCardImage)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                //Server Validation
                //var validationResult = new AddBankAccountValidator(_repository, _brandRepository).Validate(data);
                //if (!validationResult.IsValid)
                //{
                //    throw new RegoException(validationResult.Errors.First().ErrorMessage);
                //    //throw validationResult.GetValidationError();
                //}

                //var bank = _repository.Banks.Single(x => x.Id == data.Bank);
                var id         = Guid.NewGuid();
                var brandId    = Guid.Parse(data.BrandId);
                var licenseeId = Guid.Parse(data.LicenseeId);

                var frontImageId   = SaveFile(data.IdFrontImage, idFrontImage, id, brandId, licenseeId);
                var backImageId    = SaveFile(data.IdBackImage, idBackImage, id, brandId, licenseeId);
                var atmCardImageId = SaveFile(data.AtmCardImage, atmCardImage, id, brandId, licenseeId);

                var brand = _repository.Brands.Single(x => x.Id == new Guid(data.BrandId));

                var bankAccount = new BankAccount
                {
                    Id              = id,
                    Bank            = _repository.Banks.Single(x => x.Id == data.Bank),
                    CurrencyCode    = data.Currency,
                    AccountId       = data.AccountId,
                    AccountName     = data.AccountName,
                    AccountNumber   = data.AccountNumber,
                    AccountType     = _repository.BankAccountTypes.Single(x => x.Id == data.AccountType),
                    Province        = data.Province,
                    Branch          = data.Branch,
                    Remarks         = data.Remarks,
                    SupplierName    = data.SupplierName,
                    ContactNumber   = data.ContactNumber,
                    USBCode         = data.USBCode,
                    PurchasedDate   = DateTime.Parse(data.PurchasedDate),
                    UtilizationDate = DateTime.Parse(data.UtilizationDate),
                    ExpirationDate  = DateTime.Parse(data.ExpirationDate),
                    IdFrontImage    = frontImageId,
                    IdBackImage     = backImageId,
                    ATMCardImage    = atmCardImageId,
                    Status          = BankAccountStatus.Pending,
                    Created         = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                    CreatedBy       = _actorInfoProvider.Actor.UserName
                };

                _repository.BankAccounts.Add(bankAccount);
                _repository.SaveChanges();

                var bankAccountAdded = new BankAccountAdded
                {
                    Id                = bankAccount.Id,
                    AccountId         = bankAccount.AccountId,
                    BankId            = bankAccount.Bank.Id,
                    BankAccountStatus = bankAccount.Status,
                    CreatedBy         = bankAccount.CreatedBy,
                    CreatedDate       = bankAccount.Created,
                    EventCreated      = bankAccount.Created,
                    Remarks           = bankAccount.Remarks
                };

                _eventBus.Publish(bankAccountAdded);

                scope.Complete();

                return(bankAccount.Id);
            }
        }
Beispiel #16
0
        public void AssignBrandCurrency(AssignBrandCurrencyRequest assignBrandCurrencyRequest)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = ValidateThatBrandCurrencyCanBeAssigned(assignBrandCurrencyRequest);

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

                var brand = _repository.Brands
                            .Include(x => x.BrandCurrencies)
                            .Single(x => x.Id == assignBrandCurrencyRequest.Brand);

                if (brand.BrandCurrencies.Count == 0)
                {
                    brand.CurrencySetCreated   = DateTime.Now;
                    brand.CurrencySetCreatedBy = Thread.CurrentPrincipal.Identity.Name;
                }
                else
                {
                    var oldCurrencies = brand.BrandCurrencies
                                        .Where(x => !assignBrandCurrencyRequest.Currencies.Contains(x.CurrencyCode))
                                        .ToArray();

                    foreach (var oldCurrency in oldCurrencies)
                    {
                        brand.BrandCurrencies.Remove(oldCurrency);
                    }

                    brand.CurrencySetUpdated   = DateTime.Now;
                    brand.CurrencySetUpdatedBy = Thread.CurrentPrincipal.Identity.Name;
                }

                brand.DefaultCurrency = assignBrandCurrencyRequest.DefaultCurrency;
                brand.BaseCurrency    = assignBrandCurrencyRequest.BaseCurrency;

                var newCurrencies =
                    assignBrandCurrencyRequest.Currencies.Where(x => brand.BrandCurrencies.All(y => y.CurrencyCode != x));

                foreach (var currency in newCurrencies
                         .Select(newCurrency => _repository.Currencies.Single(c => c.Code == newCurrency)))
                {
                    brand.BrandCurrencies.Add(new BrandCurrency
                    {
                        BrandId      = brand.Id,
                        Brand        = brand,
                        CurrencyCode = currency.Code,
                        Currency     = currency,
                        DateAdded    = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                        AddedBy      = _actorInfoProvider.Actor.UserName
                    });
                }

                brand.DateUpdated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId);
                brand.UpdatedBy   = _actorInfoProvider.Actor.UserName;

                _repository.SaveChanges();
                _eventBus.Publish(new BrandCurrenciesAssigned
                {
                    BrandId         = brand.Id,
                    Currencies      = brand.BrandCurrencies.Select(bc => bc.CurrencyCode).ToArray(),
                    DefaultCurrency = brand.DefaultCurrency,
                    BaseCurrency    = brand.BaseCurrency,
                    EventCreated    = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });

                scope.Complete();
            }
        }
Beispiel #17
0
        public void Consume(Interface.Commands.WithdrawRequestCancel command)
        {
            var paymentRepository = _container.Resolve <IPaymentRepository>();
            var serviceBus        = _container.Resolve <IServiceBus>();
            var brandOperations   = _container.Resolve <IBrandOperations>();

            var withdrawal = paymentRepository.OfflineWithdraws
                             .Include(x => x.PlayerBankAccount.Player)
                             .FirstOrDefault(x => x.Id == command.WithdrawId);

            if (withdrawal == null)
            {
                throw new RegoException(string.Format(WithdrawRecordNotFoundMessage, command.WithdrawId));
            }

            if (command.Status == WithdrawalStatus.Unverified)
            {
                if (withdrawal.Status != WithdrawalStatus.AutoVerificationFailed &&
                    withdrawal.Status != WithdrawalStatus.Reverted &&
                    withdrawal.Status != WithdrawalStatus.Investigation &&
                    withdrawal.Status != WithdrawalStatus.Documents)
                {
                    throw new InvalidOperationException(string.Format("The withdrawal has \"{0}\" status, so it can't be {1}, id:{2}", withdrawal.Status, "Unverified", command.WithdrawId));
                }
            }

            //Put the money back to game domain
            var gameBalance = brandOperations.FundIn(withdrawal.PlayerBankAccount.Player.Id, withdrawal.Amount,
                                                     withdrawal.PlayerBankAccount.Player.CurrencyCode, withdrawal.TransactionNumber + "-C");

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                withdrawal.Remarks = command.Remarks;
                withdrawal.Status  = command.Status;
                if (command.Status == WithdrawalStatus.Unverified)
                {
                    withdrawal.Unverified   = command.Canceled;
                    withdrawal.UnverifiedBy = command.ActorName;
                }
                else
                {
                    withdrawal.CanceledTime = command.Canceled;
                    withdrawal.CanceledBy   = command.ActorName;
                }

                var eventCreated = DateTimeOffset.Now.ToOffset(command.Canceled.Offset);

                //UnLock WithdrawLock
                var withdrawLock =
                    paymentRepository.WithdrawalLocks.FirstOrDefault(x => x.WithdrawalId == command.WithdrawId);
                withdrawLock.Status     = Status.Inactive;
                withdrawLock.UnLockedBy = command.ActorName;
                withdrawLock.UnLockedOn = eventCreated;

                paymentRepository.SaveChanges();

                //raise WithdrawalCancel event
                var withdrawalCancelledEvent = new WithdrawalCancelled(
                    command.WithdrawId,
                    withdrawal.Amount,
                    eventCreated,
                    command.CanceledUserId,
                    withdrawal.PlayerBankAccount.Player.Id,
                    command.Status,
                    command.Remarks,
                    withdrawal.TransactionNumber,
                    command.ActorName)
                {
                    EventCreated   = eventCreated,
                    EventCreatedBy = command.ActorName,
                };

                serviceBus.PublishMessage(withdrawalCancelledEvent);

                scope.Complete();
            }
        }
Beispiel #18
0
        public Guid AddVipLevel(VipLevelViewModel model)
        {
            var validationResult = ValidateThatVipLevelCanBeAdded(model);

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

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var brand = _repository.Brands.Include(x => x.VipLevels).Single(x => x.Id == model.Brand);

                var vipLevel = new VipLevel
                {
                    Id          = model.Id ?? Guid.NewGuid(),
                    BrandId     = brand.Id,
                    Code        = model.Code,
                    Name        = model.Name,
                    Rank        = model.Rank,
                    Description = model.Description,
                    ColorCode   = model.Color,
                    CreatedBy   = _actorInfoProvider.Actor.UserName,
                    DateCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId)
                };

                var vipLevelLimits = model.Limits.Select(x => new VipLevelGameProviderBetLimit
                {
                    Id             = Guid.NewGuid(),
                    VipLevel       = vipLevel,
                    GameProviderId = x.GameProviderId.Value,
                    Currency       = _repository.Currencies.Single(y => y.Code == x.CurrencyCode),
                    BetLimitId     = x.BetLimitId.Value
                }).ToList();

                vipLevel.VipLevelGameProviderBetLimits = vipLevelLimits;

                _repository.VipLevels.Add(vipLevel);
                brand.VipLevels.Add(vipLevel);
                _repository.SaveChanges();

                _eventBus.Publish(new VipLevelRegistered
                {
                    Id          = vipLevel.Id,
                    BrandId     = vipLevel.BrandId,
                    Code        = vipLevel.Code,
                    Name        = vipLevel.Name,
                    Rank        = vipLevel.Rank,
                    Description = vipLevel.Description,
                    ColorCode   = vipLevel.ColorCode,
                    Status      = vipLevel.Status,

                    VipLevelLimits = vipLevel.VipLevelGameProviderBetLimits.Select(x => new VipLevelLimitData
                    {
                        Id             = x.Id,
                        VipLevelId     = vipLevel.Id,
                        CurrencyCode   = x.Currency.Code,
                        GameProviderId = x.GameProviderId,
                        BetLimitId     = x.BetLimitId
                    }).ToArray(),
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });

                if (model.IsDefault)
                {
                    SetDefaultVipLevel(brand, vipLevel.Id);
                }

                scope.Complete();

                return(vipLevel.Id);
            }
        }
 TransactionScope ITransactionScopeProvider.GetTransactionScope()
 {
     return(CustomTransactionScope.GetTransactionScope());
 }
Beispiel #20
0
        public void Consume(Interface.Commands.WithdrawRequestSubmit command)
        {
            var paymentRepository = _container.Resolve <IPaymentRepository>();
            var brandOperations   = _container.Resolve <IBrandOperations>();
            var serviceBus        = _container.Resolve <IServiceBus>();
            var withdrawalService = _container.Resolve <IWithdrawalService>();

            //move money out of Game service
            var player      = paymentRepository.Players.FirstOrDefault(x => x.Id == command.PlayerId);
            var gameBalance = brandOperations.FundOut(command.PlayerId, command.Amount, player.CurrencyCode, command.ReferenceCode);

            var bankAccount =
                paymentRepository.PlayerBankAccounts.Include(x => x.Player)
                .Include(x => x.Bank)
                .SingleOrDefault(x => x.Id == command.PlayerBankAccountId);

            bankAccount.EditLock = true;

            var withdrawal = new Data.OfflineWithdraw();

            withdrawal.Id = command.WithdrawId;
            withdrawal.PlayerBankAccount = bankAccount;
            withdrawal.TransactionNumber = command.ReferenceCode;
            withdrawal.Amount            = command.Amount;
            withdrawal.CreatedBy         = command.RequestedBy;
            withdrawal.Created           = command.Requested;
            withdrawal.Remarks           = command.Remarks;
            withdrawal.Status            = WithdrawalStatus.New;

            //lock money for withdrawal in our wallet
            var withdrawalLock = new WithdrawalLock
            {
                Id           = command.LockId,
                PlayerId     = command.PlayerId,
                WithdrawalId = command.WithdrawId,
                Amount       = command.Amount,
                Status       = Status.Active,
                LockedOn     = DateTimeOffset.Now.ToOffset(command.Requested.Offset),
                LockedBy     = command.RequestedBy
            };

            var eventCreated = DateTimeOffset.Now.ToOffset(command.Requested.Offset);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                paymentRepository.OfflineWithdraws.Add(withdrawal);
                paymentRepository.WithdrawalLocks.Add(withdrawalLock);
                paymentRepository.SaveChanges();

                //raise WithdrawalCreated event
                var withdrawalCreatedEvent = new WithdrawalCreated(
                    command.WithdrawId,
                    command.Amount,
                    eventCreated,
                    command.PlayerId,
                    command.PlayerId,
                    WithdrawalStatus.New,
                    command.Remarks,
                    command.ReferenceCode,
                    command.ActorName)
                {
                    EventCreated   = eventCreated,
                    EventCreatedBy = command.ActorName,
                };

                serviceBus.PublishMessage(withdrawalCreatedEvent);

                scope.Complete();

                //TODO:AFTREGO-4131 implement behavior stated below:
                //there is still as small chance that some amount will be spent in Game subdomain
                //after we performed balance check and before money removed from Game balance
                //it means that we need to detect such situation by performing additional validations after WithdrawRequestSubmitted event
                //and automatically reject withdrawal request if some inconsistencies were found
            }
            withdrawalService.WithdrawalStateMachine(command.WithdrawId);
        }
        public Guid Add(AddLicenseeData data)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = _licenseeQueries.ValidateCanAdd(data);

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

                var licensee = new Licensee
                {
                    Id                  = data.Id ?? Guid.NewGuid(),
                    Name                = data.Name,
                    CompanyName         = data.CompanyName,
                    AffiliateSystem     = data.AffiliateSystem,
                    ContractStart       = data.ContractStart,
                    ContractEnd         = data.ContractEnd,
                    Email               = data.Email,
                    AllowedBrandCount   = data.BrandCount,
                    AllowedWebsiteCount = data.WebsiteCount,
                    TimezoneId          = data.TimeZoneId,
                    Status              = LicenseeStatus.Inactive,
                    DateCreated         = DateTimeOffset.UtcNow,
                    CreatedBy           = _actorInfoProvider.Actor.UserName,
                    Contracts           = new List <Contract>
                    {
                        new Contract
                        {
                            Id                = Guid.NewGuid(),
                            StartDate         = data.ContractStart,
                            EndDate           = data.ContractEnd,
                            IsCurrentContract = true
                        }
                    }
                };

                if (data.Products != null)
                {
                    EnumerableExtensions.ForEach(data.Products, x =>
                                                 licensee.Products.Add(new LicenseeProduct
                    {
                        ProductId = new Guid(x)
                    }));
                }

                EnumerableExtensions.ForEach(data.Currencies, x => licensee.Currencies.Add(_repository.Currencies.Single(y => y.Code == x)));
                EnumerableExtensions.ForEach(data.Countries, x => licensee.Countries.Add(_repository.Countries.Single(y => y.Code == x)));
                EnumerableExtensions.ForEach(data.Languages, x => licensee.Cultures.Add(_repository.Cultures.Single(y => y.Code == x)));

                _repository.Licensees.Add(licensee);
                _repository.SaveChanges();

                _eventBus.Publish(new LicenseeCreated
                {
                    Id              = licensee.Id,
                    Name            = licensee.Name,
                    CompanyName     = licensee.CompanyName,
                    Email           = licensee.Email,
                    AffiliateSystem = licensee.AffiliateSystem,
                    ContractStart   = licensee.ContractStart,
                    ContractEnd     = licensee.ContractEnd,
                    Languages       = licensee.Cultures.Select(c => c.Code)
                });

                scope.Complete();

                return(licensee.Id);
            }
        }
Beispiel #22
0
        public Admin CreateAdmin(AddAdminData data)
        {
            var validationResult = new AddAdminValidator(_repository).Validate(data);

            if (!validationResult.IsValid)
            {
                throw new RegoException(validationResult.Errors.First().ErrorMessage);
            }

            //todo: KB: not sure how input role id can be null. And if it is validation should trigger
            var role = _repository.Roles.SingleOrDefault(r => r.Id == (data.RoleId ?? new Guid("00000000-0000-0000-0000-000000000002")));

            var admin = Mapper.DynamicMap <Admin>(data);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                admin.Id = Guid.NewGuid();

                admin.Role = role;

                admin.SetLicensees(data.AssignedLicensees);

                admin.SetAllowedBrands(data.AllowedBrands);

                admin.SetCurrencies(data.Currencies);

                if (data.AllowedBrands != null)
                {
                    foreach (var allowedBrand in data.AllowedBrands)
                    {
                        admin.BrandFilterSelections.Add(new BrandFilterSelection
                        {
                            AdminId = admin.Id,
                            BrandId = allowedBrand,
                            Admin   = admin
                        });
                    }
                }

                _authCommands.CreateActor(new CreateActor
                {
                    ActorId  = admin.Id,
                    Username = admin.Username,
                    Password = data.Password
                });
                _authCommands.AssignRoleToActor(new AssignRole
                {
                    ActorId = admin.Id,
                    RoleId  = role.Id
                });

                _repository.Admins.Add(admin);
                _repository.SaveChanges();

                _eventBus.Publish(new AdminCreated(admin));

                scope.Complete();
            }

            return(admin);
        }
Beispiel #23
0
        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);
            }
        }