public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var pages = await _pageService.GetAreaPagesAsync(NavPages); if (!NavPages) { output.Attributes.Add("class", "infolinks"); output.TagName = "div"; } else { output.TagName = ""; } if (pages.Any()) { IUrlHelper url = _urlHelperFactory.GetUrlHelper(ViewContext); string activeStub = url.ActionContext.RouteData.Values["id"] as string; var first = true; foreach (var page in pages) { var link = url.Action(nameof(InfoController.Index), InfoController.Name, new { id = page.PageStub }); if (first) { first = false; } else { output.Content.Append(NavPages ? " " : " | "); } TagBuilder outputTag; var aTag = new TagBuilder("a"); aTag.Attributes.Add("href", link); aTag.InnerHtml.AppendHtml(NavPages ? page.NavText : page.FooterText); if (NavPages) { outputTag = new TagBuilder("li"); outputTag.InnerHtml.AppendHtml(aTag); } else { outputTag = aTag; } if (page.PageStub == activeStub) { outputTag.AddCssClass("active"); } output.Content.AppendHtml(outputTag); } } var siteId = (int)ViewContext .HttpContext .Items[ItemKey.SiteId]; var userClaim = ViewContext .HttpContext .User .Claims .SingleOrDefault(_ => _.Type == ClaimType.UserId); if (!NavPages && siteId != 0) { bool linkToLibrary = await _siteLookupService.GetSiteSettingBoolAsync(siteId, SiteSettingKey.Users.ShowLinkToParticipantsLibrary); bool showParticipatingLibraries = await _siteLookupService .GetSiteSettingBoolAsync(siteId, SiteSettingKey.Users.ShowLinkToParticipatingLibraries); if (linkToLibrary || showParticipatingLibraries) { var divTag = new TagBuilder("div"); divTag.AddCssClass("locations"); if (showParticipatingLibraries) { var allBranchesLink = new TagBuilder("a"); allBranchesLink.InnerHtml.AppendHtml(_sharedLocalizer[Annotations .Interface .AllParticipatingLibraries]); IUrlHelper url = _urlHelperFactory.GetUrlHelper(ViewContext); allBranchesLink.MergeAttribute("href", url.Action(nameof(ParticipatingLibrariesController.Index), ParticipatingLibrariesController.Name)); divTag.InnerHtml.AppendHtml(allBranchesLink); } if (linkToLibrary && userClaim != null && int.TryParse(userClaim.Value, out int userId)) { var branch = await _userService.GetUsersBranch(userId); if (!string.IsNullOrEmpty(branch.Url)) { var branchLink = new TagBuilder("a"); branchLink .InnerHtml .AppendHtml(_sharedLocalizer[Annotations.Interface.Explore, branch.Name]); branchLink.MergeAttribute("href", branch.Url); if (showParticipatingLibraries) { divTag.InnerHtml.AppendHtml(" | "); } divTag.InnerHtml.AppendHtml(branchLink); } } output.Content.AppendHtml(divTag); } } }
/// <summary> /// Look up a boolean site setting by key. /// </summary> /// <param name="key">The site setting key value (a string, up to 255 characters)</param> /// <returns>True if the value is set in the database, false if the key is not present or /// set to NULL.</returns> protected async Task <bool> GetSiteSettingBoolAsync(string key) { return(await _siteLookupService.GetSiteSettingBoolAsync(GetCurrentSiteId(), key)); }
public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) { var httpContext = context.HttpContext; try { var userId = _userContextProvider.GetId(httpContext.User, ClaimType.UserId); var activeId = httpContext.Session.GetInt32(SessionKey.ActiveUserId); if (userId != activeId) { httpContext.Session.SetInt32(SessionKey.ActiveUserId, userId); var user = await _userService.GetDetails(userId); var questionnaireId = await _questionnaireService .GetRequiredQuestionnaire(user.Id, user.Age); if (questionnaireId.HasValue) { httpContext.Session.SetInt32(SessionKey.PendingQuestionnaire, questionnaireId.Value); } else { httpContext.Session.Remove(SessionKey.PendingQuestionnaire); } } } catch (Exception ex) { _logger.LogTrace($"Attempted Mission Control access while not logged in: {ex.Message}"); } if (httpContext.User.HasClaim(ClaimType.Permission, nameof(Permission.ReadAllMail))) { try { httpContext.Items[ItemKey.UnreadCount] = await _mailService.GetAdminUnreadCountAsync(); } catch (Exception ex) { _logger.LogError("Error getting admin mail unread count: {Message}", ex.Message); } } if (httpContext.User.HasClaim(ClaimType.Permission, nameof(Permission.ViewPerformerDetails))) { var settings = await _performerSchedulingService.GetSettingsAsync(); var schedulingStage = _performerSchedulingService .GetSchedulingStage(settings); if (schedulingStage != PsSchedulingStage.Unavailable) { httpContext.Items.Add(ItemKey.ShowPerformerScheduling, true); } } var siteId = httpContext.Session.GetInt32(SessionKey.SiteId); if (siteId != null && await _siteLookupService.GetSiteSettingBoolAsync((int)siteId, SiteSettingKey.VendorCodes.ShowPackingSlip)) { httpContext.Items.Add(ItemKey.ShowPackingSlips, true); } await next(); }