Beispiel #1
0
        public async Task <IActionResult> Edit(int id)
        {
            var trigger = await _triggerService.GetByIdAsync(id);

            var site = await GetCurrentSiteAsync();

            var siteUrl = await _siteService.GetBaseUrl(Request.Scheme, Request.Host.Value);

            TriggersDetailViewModel viewModel = new TriggersDetailViewModel()
            {
                Trigger             = trigger,
                Action              = "Edit",
                IsSecretCode        = !string.IsNullOrWhiteSpace(trigger.SecretCode),
                BadgeMakerUrl       = GetBadgeMakerUrl(siteUrl, site.FromEmailAddress),
                UseBadgeMaker       = true,
                DependentTriggers   = await _triggerService.GetDependentsAsync(trigger.AwardBadgeId),
                TriggerRequirements = await _triggerService.GetTriggerRequirementsAsync(trigger),
                BadgeRequiredList   = string.Join("", trigger.BadgeIds
                                                  .Select(_ => "<" + _.ToString() + ">")),
                ChallengeRequiredList = string.Join("", trigger.ChallengeIds
                                                    .Select(_ => "<" + _.ToString() + ">")),
                SystemList         = new SelectList((await _siteService.GetSystemList()), "Id", "Name"),
                BranchList         = new SelectList((await _siteService.GetAllBranches()), "Id", "Name"),
                ProgramList        = new SelectList((await _siteService.GetProgramList()), "Id", "Name"),
                VendorCodeTypeList = new SelectList(
                    (await _vendorCodeService.GetTypeAllAsync()), "Id", "Name")
            };

            foreach (var requirement in viewModel.TriggerRequirements)
            {
                if (!string.IsNullOrWhiteSpace(requirement.BadgePath))
                {
                    requirement.BadgePath = _pathResolver.ResolveContentPath(requirement.BadgePath);
                }
            }
            if (!string.IsNullOrWhiteSpace(viewModel.Trigger.AwardBadgeFilename))
            {
                viewModel.BadgePath = _pathResolver.ResolveContentPath(viewModel.Trigger.AwardBadgeFilename);
            }
            PageTitle = $"Edit Trigger - {viewModel.Trigger.Name}";
            return(View("Detail", viewModel));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id)
        {
            var trigger = await _triggerService.GetByIdAsync(id);

            if (trigger == null)
            {
                ShowAlertWarning($"Could not find trigger id {id}, possibly it has been deleted.");
                return(RedirectToAction("Index"));
            }
            var site = await GetCurrentSiteAsync();

            var siteUrl = await _siteService.GetBaseUrl(Request.Scheme, Request.Host.Value);

            var badge = await _badgeService.GetByIdAsync(trigger.AwardBadgeId);

            var viewModel = new TriggersDetailViewModel
            {
                Trigger             = trigger,
                CreatedByName       = await _userService.GetUsersNameByIdAsync(trigger.CreatedBy),
                CanViewParticipants = UserHasPermission(Permission.ViewParticipantDetails),
                Action                = "Edit",
                IsSecretCode          = !string.IsNullOrWhiteSpace(trigger.SecretCode),
                BadgeMakerUrl         = GetBadgeMakerUrl(siteUrl, site.FromEmailAddress),
                UseBadgeMaker         = true,
                EditAvatarBundle      = UserHasPermission(Permission.ManageAvatars),
                EditMail              = UserHasPermission(Permission.ManageTriggerMail),
                EditVendorCode        = UserHasPermission(Permission.ManageVendorCodes),
                AwardsMail            = !string.IsNullOrWhiteSpace(trigger.AwardMailSubject),
                AwardsPrize           = !string.IsNullOrWhiteSpace(trigger.AwardPrizeName),
                DependentTriggers     = await _triggerService.GetDependentsAsync(trigger.AwardBadgeId),
                TriggerRequirements   = await _triggerService.GetTriggerRequirementsAsync(trigger),
                BadgeRequiredList     = string.Join(",", trigger.BadgeIds),
                ChallengeRequiredList = string.Join(",", trigger.ChallengeIds),
                SystemList            = new SelectList(await _siteService.GetSystemList(), "Id", "Name"),
                ProgramList           = new SelectList(await _siteService.GetProgramList(), "Id", "Name"),
                IgnorePointLimits     = UserHasPermission(Permission.IgnorePointLimits),
                MaxPointLimit         =
                    await _triggerService.GetMaximumAllowedPointsAsync(GetCurrentSiteId()),
                BadgeAltText = badge.AltText
            };

            if (viewModel?.MaxPointLimit != null)
            {
                viewModel.MaxPointsMessage = $"(Up to {viewModel.MaxPointLimit.Value} points)";
            }
            if (trigger.AwardPoints > viewModel.MaxPointLimit)
            {
                viewModel.MaxPointsWarningMessage = $"This Trigger exceeds the maximum of {viewModel.MaxPointLimit.Value} points per required task. Only Administrators can edit the points awarded.";
            }
            if (viewModel.EditVendorCode)
            {
                viewModel.VendorCodeTypeList = new SelectList(
                    await _vendorCodeService.GetTypeAllAsync(), "Id", "Description");
            }
            else if (viewModel.Trigger.AwardVendorCodeTypeId.HasValue)
            {
                viewModel.VendorCodeType = (await _vendorCodeService
                                            .GetTypeById(viewModel.Trigger.AwardVendorCodeTypeId.Value)).Description;
            }

            if (viewModel.EditAvatarBundle)
            {
                viewModel.UnlockableAvatarBundleList = new SelectList(
                    await _avatarService.GetAllBundlesAsync(true), "Id", "Name");
            }
            else if (viewModel.Trigger.AwardAvatarBundleId.HasValue)
            {
                viewModel.UnlockableAvatarBundle = (await _avatarService
                                                    .GetBundleByIdAsync(viewModel.Trigger.AwardAvatarBundleId.Value)).Name;
            }

            if (viewModel.Trigger.LimitToSystemId.HasValue)
            {
                viewModel.BranchList = new SelectList(
                    await _siteService.GetBranches(viewModel.Trigger.LimitToSystemId.Value), "Id", "Name");
            }
            else
            {
                viewModel.BranchList = new SelectList(await _siteService.GetAllBranches(), "Id", "Name");
            }
            foreach (var requirement in viewModel.TriggerRequirements)
            {
                if (!string.IsNullOrWhiteSpace(requirement.BadgePath))
                {
                    requirement.BadgePath = _pathResolver.ResolveContentPath(requirement.BadgePath);
                }
            }
            if (!string.IsNullOrWhiteSpace(viewModel.Trigger.AwardBadgeFilename))
            {
                viewModel.BadgePath = _pathResolver.ResolveContentPath(viewModel.Trigger.AwardBadgeFilename);
            }
            if (UserHasPermission(Permission.ManageEvents))
            {
                viewModel.RelatedEvents = await _eventService.GetRelatedEventsForTriggerAsync(id);
            }
            PageTitle = $"Edit Trigger - {viewModel.Trigger.Name}";
            return(View("Detail", viewModel));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id)
        {
            var trigger = await _triggerService.GetByIdAsync(id);

            var site = await GetCurrentSiteAsync();

            var siteUrl = await _siteService.GetBaseUrl(Request.Scheme, Request.Host.Value);

            var viewModel = new TriggersDetailViewModel
            {
                Trigger               = trigger,
                Action                = "Edit",
                IsSecretCode          = !string.IsNullOrWhiteSpace(trigger.SecretCode),
                BadgeMakerUrl         = GetBadgeMakerUrl(siteUrl, site.FromEmailAddress),
                UseBadgeMaker         = true,
                EditAvatarBundle      = UserHasPermission(Permission.ManageAvatars),
                EditMail              = UserHasPermission(Permission.ManageTriggerMail),
                EditVendorCode        = UserHasPermission(Permission.ManageVendorCodes),
                AwardsMail            = !string.IsNullOrWhiteSpace(trigger.AwardMailSubject),
                AwardsPrize           = !string.IsNullOrWhiteSpace(trigger.AwardPrizeName),
                DependentTriggers     = await _triggerService.GetDependentsAsync(trigger.AwardBadgeId),
                TriggerRequirements   = await _triggerService.GetTriggerRequirementsAsync(trigger),
                BadgeRequiredList     = string.Join(",", trigger.BadgeIds),
                ChallengeRequiredList = string.Join(",", trigger.ChallengeIds),
                SystemList            = new SelectList((await _siteService.GetSystemList()), "Id", "Name"),
                ProgramList           = new SelectList((await _siteService.GetProgramList()), "Id", "Name")
            };

            if (viewModel.EditVendorCode)
            {
                viewModel.VendorCodeTypeList = new SelectList(
                    (await _vendorCodeService.GetTypeAllAsync()), "Id", "Description");
            }
            else if (viewModel.Trigger.AwardVendorCodeTypeId.HasValue)
            {
                viewModel.VendorCodeType = (await _vendorCodeService
                                            .GetTypeById(viewModel.Trigger.AwardVendorCodeTypeId.Value)).Description;
            }

            if (viewModel.EditAvatarBundle)
            {
                viewModel.UnlockableAvatarBundleList = new SelectList(
                    await _dynamicAvatarService.GetAllBundlesAsync(true), "Id", "Name");
            }
            else if (viewModel.Trigger.AwardAvatarBundleId.HasValue)
            {
                viewModel.UnlockableAvatarBundle = (await _dynamicAvatarService
                                                    .GetBundleByIdAsync(viewModel.Trigger.AwardAvatarBundleId.Value)).Name;
            }

            if (viewModel.Trigger.LimitToSystemId.HasValue)
            {
                viewModel.BranchList = new SelectList(
                    (await _siteService.GetBranches(viewModel.Trigger.LimitToSystemId.Value)), "Id", "Name");
            }
            else
            {
                viewModel.BranchList = new SelectList((await _siteService.GetAllBranches()), "Id", "Name");
            }
            foreach (var requirement in viewModel.TriggerRequirements)
            {
                if (!string.IsNullOrWhiteSpace(requirement.BadgePath))
                {
                    requirement.BadgePath = _pathResolver.ResolveContentPath(requirement.BadgePath);
                }
            }
            if (!string.IsNullOrWhiteSpace(viewModel.Trigger.AwardBadgeFilename))
            {
                viewModel.BadgePath = _pathResolver.ResolveContentPath(viewModel.Trigger.AwardBadgeFilename);
            }

            if (UserHasPermission(Permission.ManageEvents))
            {
                viewModel.RelatedEvents = await _eventService.GetRelatedEventsForTriggerAsync(id);
            }
            PageTitle = $"Edit Trigger - {viewModel.Trigger.Name}";
            return(View("Detail", viewModel));
        }