Пример #1
0
        private async Task <IEnumerable <UserTargeting> > GetRules(Guid environmentId)
        {
            var rules    = unitOfWork.Repository <UserTargeting, Guid>();
            var envRules = await rules.GetAsync(UserTargeting.ByEnvironment(environmentId), "FeatureToggle,TargetRule");

            return(envRules);
        }
Пример #2
0
        public async Task <IEnumerable <UserTargeting> > GetTargets(Guid environmentId)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasEnvironmentPermission.ToRead(userId, environmentId));

            var userTargetings = unitOfWork.Repository <UserTargeting, Guid>();

            return(await userTargetings.GetAsync(UserTargeting.ByEnvironment(environmentId), "FeatureToggle,TargetRule"));
        }
Пример #3
0
        public async Task CreatePerPercent(Guid applicationId, Guid environmentId, Guid featureToggleId, int percent)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasEnvironmentPermission.ToWrite(userId, environmentId), "You don't have permissions to create");

            var userTargetings = unitOfWork.Repository <UserTargeting, Guid>();


            Guard.IsFalse(await userTargetings.AnyAsync(UserTargeting.ByEnvironment(environmentId).And(UserTargeting.ByToggle(featureToggleId))), "Already exists a rule for this environment and this feature toggle");

            var target = UserTargeting.PerPercent(environmentId, featureToggleId, percent);

            userTargetings.Insert(target);

            await unitOfWork.SaveAsync();
        }