public Guid ApplyForBonus(DepositBonusApplication model)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = _bonusQueries.GetValidationResult(model);
                if (validationResult.IsValid == false)
                {
                    throw new RegoException(validationResult.Errors.First().ErrorMessage);
                }

                var player           = _repository.GetLockedPlayer(model.PlayerId);
                var redemptionParams = new RedemptionParams
                {
                    TransferAmount           = model.Amount,
                    TransferExternalId       = model.DepositId,
                    TransferWalletTemplateId = player.Data.Brand.WalletTemplates.Single(wt => wt.IsMain).Id
                };
                var bonusId    = model.BonusId ?? _repository.GetLockedBonus(model.BonusCode).Data.Id;
                var redemption = RedeemBonus(model.PlayerId, bonusId, redemptionParams);
                redemption.Events.ForEach(_eventBus.Publish);
                scope.Complete();

                return(redemption.Data.Id);
            }
        }
        public List <QualifiedTransaction> GetManualByCsQualifiedTransactions(Guid playerId, Guid bonusId)
        {
            var player = _repository.GetLockedPlayer(playerId);
            var bonus  = _repository.GetLockedBonus(bonusId);

            return(bonus.GetQualifiedTransactions(player).ToList());
        }
Exemple #3
0
        public DepositBonusApplicationValidator(IBonusRepository repository)
        {
            RuleFor(m => m.PlayerId)
            .Must(playerId => repository.Players.Any(p => p.Id == playerId))
            .WithMessage(ValidatorMessages.PlayerDoesNotExist)
            .DependentRules(rules =>
            {
                rules.RuleFor(m => m)
                .Must(m =>
                {
                    var bonus = m.BonusId.HasValue
                                ? repository.GetLockedBonusOrNull(m.BonusId.Value)
                                : repository.GetLockedBonusOrNull(m.BonusCode);

                    if (bonus != null)
                    {
                        if ((bonus.Data.Template.Info.TemplateType != BonusType.FirstDeposit &&
                             bonus.Data.Template.Info.TemplateType != BonusType.ReloadDeposit) ||
                            (bonus.Data.Template.Info.Mode != IssuanceMode.AutomaticWithCode &&
                             bonus.Data.Template.Info.Mode != IssuanceMode.ManualByPlayer))
                        {
                            return(false);
                        }

                        return(true);
                    }

                    return(false);
                })
                .WithMessage(ValidatorMessages.BonusDoesNotExist)
                .WithName("Model")
                .DependentRules(dependentRules =>
                {
                    string error = null;
                    dependentRules.RuleFor(m => m)
                    .Must(m =>
                    {
                        var bonus = m.BonusId.HasValue
                                        ? repository.GetLockedBonus(m.BonusId.Value)
                                        : repository.GetLockedBonus(m.BonusCode);

                        var player = repository.GetLockedPlayer(m.PlayerId);
                        var errors = bonus.QualifyFor(player, QualificationPhase.Redemption,
                                                      new RedemptionParams {
                            TransferAmount = m.Amount
                        }).ToArray();
                        if (errors.Any())
                        {
                            error = errors.First();
                            return(false);
                        }

                        return(true);
                    })
                    .WithMessage("{0}", application => error)
                    .WithName("Model");
                });
            });

            RuleFor(m => m.DepositId)
            .NotEmpty()
            .WithMessage(ValidatorMessages.DepositIdIsEmpty);
        }