-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add form headless to musicfestival backend and add sample form
Fixes: AFORM-4107 Story: AFORM-3507
- Loading branch information
Linh Hoang
committed
May 3, 2024
1 parent
882c674
commit 9ef2a98
Showing
4 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
56 changes: 56 additions & 0 deletions
56
samples/musicfestival-backend-dotnet/Controllers/ReactController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using EPiServer.Cms.Shell; | ||
using EPiServer.Web; | ||
using EPiServer.Web.Routing; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Optimizely.Cms.Preview2.Content; | ||
using Optimizely.Cms.Preview2.Content.Models; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace AlloyMvcTemplates.Controllers; | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ReactController : ControllerBase | ||
{ | ||
private readonly IContentRepository _contentRepositoryInteApi; | ||
|
||
public ReactController(IContentRepository contentRepositoryInteApi) | ||
{ | ||
_contentRepositoryInteApi = contentRepositoryInteApi; | ||
} | ||
|
||
[HttpGet("GetFormInPageByUrl")] | ||
public async Task<IActionResult> GetFormInPageByUrl(string url) | ||
{ | ||
var builder = new EPiServer.UrlBuilder(url); | ||
var content = UrlResolver.Current.Route(builder, ContextMode.Default); | ||
|
||
if (content is null) | ||
{ | ||
return NoContent(); | ||
} | ||
CancellationTokenSource source = new CancellationTokenSource(); | ||
CancellationToken token = source.Token; | ||
var key = ContentKey.FormatAsKey(content.ContentGuid); | ||
var pageModel = new PageModel(); | ||
var contentHeadless = await _contentRepositoryInteApi.GetAsync(key, content.LanguageBranch()); | ||
|
||
pageModel.Title = contentHeadless.DisplayName; | ||
pageModel.PageUrl = UrlResolver.Current.GetUrl(content.ContentLink); | ||
|
||
if (contentHeadless.Properties.ContainsKey("MainContentArea")) | ||
{ | ||
pageModel.Childrens.AddRange(contentHeadless.Properties["MainContentArea"] as IList<IContentComponent>); | ||
} | ||
|
||
return Ok(pageModel); | ||
} | ||
} | ||
|
||
public class PageModel | ||
{ | ||
public string Title { get; set; } | ||
public string PageUrl { get; set; } | ||
public List<IContentComponent> Childrens { get; set; } = new List<IContentComponent>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters