public TemplateDeletionValidator(BonusQueries queries)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor(model => model)
            .Must(model => queries.GetCurrentVersionTemplates().Any(t => t.Id == model.TemplateId))
            .WithMessage(ValidatorMessages.TemplateDoesNotExist)
            .Must(model =>
                  queries.GetCurrentVersionBonuses().Any(bonus => bonus.Template.Id == model.TemplateId) == false)
            .WithMessage(ValidatorMessages.TemplateIsInUse)
            .WithName("Template");
        }
Esempio n. 2
0
        public ToggleBonusStatusValidator(BonusQueries queries)
        {
            Func <Guid, Data.Bonus> bonusGetter =
                bonusId => queries.GetCurrentVersionBonuses().SingleOrDefault(b => b.Id == bonusId);

            RuleFor(model => model.Id)
            .Must(id => bonusGetter(id) != null)
            .WithMessage(ValidatorMessages.BonusDoesNotExist);

            RuleFor(model => model.IsActive)
            .Must((model, destStatus) =>
            {
                var bonusToValidate = bonusGetter(model.Id);
                var templateType    = bonusToValidate.Template.Info.TemplateType;
                if (templateType == BonusType.ReferFriend || templateType == BonusType.MobilePlusEmailVerification)
                {
                    var isAnyActiveBonusesOfTrigger = queries
                                                      .GetCurrentVersionBonuses()
                                                      .Where(bonus =>
                                                             bonus.Id != bonusToValidate.Id &&
                                                             bonus.Template.Info.Brand.Id == bonusToValidate.Template.Info.Brand.Id &&
                                                             bonus.IsActive)
                                                      .Any(bonus => bonus.Template.Info.TemplateType == templateType);
                    return(isAnyActiveBonusesOfTrigger == false);
                }

                return(true);
            })
            .WithMessage(ValidatorMessages.OneBonusOfATypeCanBeActive)
            .When(model =>
            {
                var bonus = bonusGetter(model.Id);
                if (bonus == null)
                {
                    return(false);
                }

                return(bonus.IsActive == false && model.IsActive);
            });
        }
Esempio n. 3
0
        public IssueByCsValidator(BonusQueries queries, IBonusRepository repository, IBrandOperations brandOperations)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;
            Func <Guid, Data.Bonus>        bonusGetter       = bonusId => queries.GetCurrentVersionBonuses().SingleOrDefault(b => b.Id == bonusId);
            Func <Guid, Player>            playerGetter      = playerId => repository.Players.SingleOrDefault(b => b.Id == playerId);
            Func <Guid, Guid, Transaction> transactionGetter = (playerId, transactionId) =>
                                                               playerGetter(playerId).Wallets.SelectMany(w => w.Transactions).SingleOrDefault(t => t.Id == transactionId);

            RuleFor(model => model.BonusId)
            .Must(id => bonusGetter(id) != null)
            .WithMessage(ValidatorMessages.BonusDoesNotExist);

            RuleFor(model => model.PlayerId)
            .Must(id => playerGetter(id) != null)
            .WithMessage(ValidatorMessages.PlayerDoesNotExist);

            When(model => playerGetter(model.PlayerId) != null && bonusGetter(model.BonusId) != null, () =>
            {
                RuleFor(model => model.TransactionId)
                .Must((model, transactionId) => transactionGetter(model.PlayerId, transactionId) != null)
                .WithMessage(ValidatorMessages.TransactionDoesNotExist);

                When(model => transactionGetter(model.PlayerId, model.TransactionId) != null, () => RuleFor(model => model.TransactionId)
                     .Must((model, transactionId) =>
                {
                    var transaction = transactionGetter(model.PlayerId, transactionId);
                    var bonus       = bonusGetter(model.BonusId);

                    if (bonus.Template.Info.TemplateType == BonusType.FundIn)
                    {
                        return(transaction.Type == TransactionType.FundIn);
                    }
                    if (bonus.Template.Info.TemplateType == BonusType.FirstDeposit || bonus.Template.Info.TemplateType == BonusType.ReloadDeposit)
                    {
                        return(transaction.Type == TransactionType.Deposit);
                    }

                    return(true);
                })
                     .WithMessage(ValidatorMessages.TransactionTypeDoesNotMatchBonusType)
                     .Must((model, transactionId) =>
                {
                    var qualifiedBonuses = queries.GetManualByCsQualifiedBonuses(model.PlayerId);
                    var theQualifedBonus = qualifiedBonuses.SingleOrDefault(b => b.Id == model.BonusId);
                    if (theQualifedBonus == null)
                    {
                        return(false);
                    }
                    var qualifiedTransactions = queries.GetManualByCsQualifiedTransactions(model.PlayerId, model.BonusId);
                    if (qualifiedTransactions.Select(tr => tr.Id).Contains(model.TransactionId) == false)
                    {
                        return(false);
                    }

                    return(true);
                })
                     .WithMessage(ValidatorMessages.PlayerIsNotQualifiedForBonus)
                     .Must((model, transactionId) =>
                {
                    var bonus = bonusGetter(model.BonusId);
                    if (bonus.Template.Wagering.HasWagering == false)
                    {
                        return(true);
                    }

                    var bonusWallet = playerGetter(model.PlayerId).Wallets.Single(w => w.Transactions.Select(t => t.Id).Contains(transactionId));
                    var transaction = transactionGetter(model.PlayerId, transactionId);

                    return(bonusWallet.Main >= transaction.TotalAmount);
                })
                     .WithMessage(ValidatorMessages.PlayerHasNoFundsToLockLeft)
                     .Must((model, transactionId) =>
                {
                    var bonus = bonusGetter(model.BonusId);
                    if (bonus.Template.Wagering.HasWagering == false)
                    {
                        return(true);
                    }

                    var player  = playerGetter(model.PlayerId);
                    var balance = brandOperations.GetPlayerBalance(model.PlayerId, player.CurrencyCode);
                    return(balance >= bonus.Template.Wagering.Threshold);
                })
                     .WithMessage(ValidatorMessages.PlayerBalanceIsLessThanWageringThreshold));
            });
        }
Esempio n. 4
0
        public BonusValidator(IBonusRepository repository, BonusQueries bonusQueries)
        {
            Func <Guid, Template> templateGetter = templateId => bonusQueries.GetCurrentVersionTemplates().SingleOrDefault(a => a.Id == templateId);

            When(bonus => bonus.Id != Guid.Empty, () =>
            {
                Func <CreateUpdateBonus, IQueryable <Data.Bonus> > bonuses = bonusVm => repository.Bonuses.Where(b => b.Id == bonusVm.Id);
                RuleFor(bonus => bonus)
                .Must(bonus => bonuses(bonus).Any())
                .WithMessage(ValidatorMessages.BonusDoesNotExist)
                .WithName("Bonus");

                RuleFor(bonus => bonus)
                .Must(bonus => bonus.Version == bonuses(bonus).Max(b => b.Version))
                .WithMessage(ValidatorMessages.BonusVersionIsNotCurrent)
                .WithName("Bonus")
                .When(bonus => bonuses(bonus).Any());
            });

            ValidateName(repository);

            RuleFor(bonus => bonus.Description)
            .NotNull()
            .WithMessage(ValidatorMessages.DescriptionIsRequired)
            .Length(1, 200)
            .WithMessage(ValidatorMessages.DescriptionLengthIsInvalid, 1, 200);

            RuleFor(bonus => bonus.DaysToClaim)
            .GreaterThanOrEqualTo(0)
            .WithMessage(ValidatorMessages.BonusDaysToClaimIsNegative);

            RuleFor(bonus => bonus.TemplateId)
            .Must(templateId => templateGetter(templateId) != null)
            .WithMessage(ValidatorMessages.BonusTemplateIsNotAssigned);

            When(b => templateGetter(b.TemplateId) != null, () =>
            {
                RuleFor(bonus => bonus.Code)
                .NotEmpty()
                .When(bonus => templateGetter(bonus.TemplateId).Info.Mode == IssuanceMode.AutomaticWithCode)
                .WithMessage(ValidatorMessages.BonusCodeIsNotSpecified);
                When(bonus => string.IsNullOrWhiteSpace(bonus.Code) == false, () => RuleFor(bonus => bonus.Code)
                     .Matches(@"^[a-zA-Z0-9]*$")
                     .WithMessage(ValidatorMessages.BonusCodeIsInvalid)
                     .Length(1, 20)
                     .WithMessage(ValidatorMessages.BonusCodeLengthIsInvalid, 1, 20)
                     .Must((bonus, code) =>
                {
                    if (bonus.Id == Guid.Empty)
                    {
                        return(bonusQueries.GetCurrentVersionBonuses().Any(b => b.Code == code) == false);
                    }

                    return(bonusQueries.GetCurrentVersionBonuses().Any(b => b.Code == code && b.Id != bonus.Id) == false);
                })
                     .WithMessage(ValidatorMessages.BonusCodeIsNotUnique));

                RuleFor(bonus => bonus.ActiveTo)
                .Must((bonus, activeTo) => activeTo > bonus.ActiveFrom)
                .WithMessage(ValidatorMessages.BonusActivityRangeIsInvalid)
                .Must((bonus, activeTo) =>
                {
                    var template   = templateGetter(bonus.TemplateId);
                    var timezoneId = template.Info.Brand.TimezoneId;
                    return(activeTo.ToBrandDateTimeOffset(timezoneId) >
                           DateTimeOffset.Now.ToBrandOffset(timezoneId));
                })
                .WithMessage(ValidatorMessages.BonusActiveToIsInvalid);

                ValidateDuration();
            });
        }