public async Task <string> GetContentItemIdFromRouteAsync(PathString url) { if (!url.HasValue) { url = "/"; } string contentItemId = null; if (url == "/") { // get contentItemId from homeroute var siteSettings = await _siteService.GetSiteSettingsAsync(); contentItemId = siteSettings.HomeRoute["contentItemId"]?.ToString(); } else { // Try to get from autorouteEntries. // This should not consider contained items, so will redirect to the parent item. (var found, var entry) = await _autorouteEntries.TryGetEntryByPathAsync(url.Value); if (found) { contentItemId = entry.ContentItemId; } } if (String.IsNullOrEmpty(contentItemId)) { return(null); } return(contentItemId); }
public async Task <IActionResult> Index(LeverPostingApplyViewModel model) { var settings = (await _siteService.GetSiteSettingsAsync()).As <LeverSettings>(); var referer = Request.Headers["Referer"].ToString(); if (!ModelState.IsValid) { return(new RedirectResult(referer)); } (var found, var contentItem) = await _autorouteEntries.TryGetEntryByPathAsync(GetReferrerRoute()); if (!found) { return(new BadRequestResult()); } var posting = await _leverPostingService.GetById(contentItem.ContentItemId); if (posting == null) { return(new BadRequestResult()); } model.PostingId = JsonConvert.DeserializeObject <Posting>(posting.GetLeverPostingPart().Data).Id; model.UpdateCards(HttpContext.Request.Form); model.UpdateSurveysResponses(HttpContext.Request.Form); var result = await _postingApiService.Apply(settings, model); if (result == null || !result.Ok) { if (result != null) { ModelState.AddModelError("error", result.Error); // If there is a validation error from API // we send the user back to the page return(new RedirectResult(referer)); } return(new RedirectResult($"{settings.SuccessUrl}")); } return(new RedirectResult($"{settings.SuccessUrl}?applicationId={result.ApplicationId}&contentItemId={contentItem.ContentItemId}" ?? "/")); }
public Task RenderingAsync(TemplateContext context) { context.MemberAccessStrategy.Register <LiquidContentAccessor, LiquidPropertyAccessor>("Slug", obj => { return(new LiquidPropertyAccessor(async alias => { if (!alias.StartsWith('/')) { alias = "/" + alias; } (var found, var entry) = await _autorouteEntries.TryGetEntryByPathAsync(alias); if (found) { return FluidValue.Create(await _contentManager.GetAsync(entry.ContentItemId, entry.JsonPath)); } return NilValue.Instance; })); });
public async Task <string> GetContentItemIdAsync(string handle) { if (handle.StartsWith("slug:", System.StringComparison.OrdinalIgnoreCase)) { handle = handle.Substring(5); if (!handle.StartsWith('/')) { handle = "/" + handle; } (var found, var entry) = await _autorouteEntries.TryGetEntryByPathAsync(handle); if (found) { // TODO this requires more work, and interface changes to support contained content items. // as it will require returning the id and jsonPath. return(entry.ContentItemId); } } return(null); }
public override async ValueTask <RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values) { (var found, var entry) = await _entries.TryGetEntryByPathAsync(httpContext.Request.Path.Value); if (found) { var routeValues = new RouteValueDictionary(_options.GlobalRouteValues) { [_options.ContentItemIdKey] = entry.ContentItemId }; if (!string.IsNullOrEmpty(entry.JsonPath)) { routeValues[_options.JsonPathKey] = entry.JsonPath; } // Prevents the original values from being re-added to the dynamic ones. values.Clear(); return(routeValues); } return(null); }