Exemple #1
0
        public async Task RemoveAsync(int triggerId)
        {
            VerifyManagementPermission();
            var dependentTriggers = await _triggerRepository.DependentTriggers(triggerId);

            if (dependentTriggers?.Count > 0)
            {
                var ex = new GraException("Trigger has dependencies");
                foreach (var dependentTrigger in dependentTriggers)
                {
                    ex.Data.Add(dependentTrigger.Key, dependentTrigger.Value);
                }
                throw ex;
            }
            var trigger = await _triggerRepository.GetByIdAsync(triggerId);

            trigger.IsDeleted    = true;
            trigger.SecretCode   = null;
            trigger.BadgeIds     = new List <int>();
            trigger.ChallengeIds = new List <int>();

            await _triggerRepository.UpdateSaveAsync(GetClaimId(ClaimType.UserId),
                                                     trigger);

            var requireSecretCode = await _siteLookupService.GetSiteSettingBoolAsync(
                GetCurrentSiteId(), SiteSettingKey.Events.RequireBadge);

            if (!requireSecretCode)
            {
                await _eventRepository.DetachRelatedTrigger(triggerId);
            }
        }