diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs index 98ac0d5e..e8da3d9a 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/EntityResolverTests.cs @@ -24,6 +24,7 @@ public class EntityResolverTests [TestCase("imageCard", typeof(ImageCard))] [TestCase("linkCard", typeof(LinkCard))] [TestCase("linkListCard", typeof(LinkListCard))] + [TestCase("resource", typeof(Resource))] [TestCase("richTextBlock", typeof(RichTextBlock))] [TestCase("roleList", typeof(RoleList))] [TestCase("sideMenu", typeof(SideMenu))] diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs index 51cb1c19..9d033bd8 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/PartialsFactoryTests.cs @@ -23,6 +23,7 @@ public partial class PartialsFactoryTests new object[] { new LinkCard(), "_LinkCard" }, new object[] { new ImageCard(), "_ImageCard" }, new object[] { new LinkListCard(), "_LinkListCard" }, + new object[] { new Resource(), "_Resource" }, new object[] { new RichTextBlock(), "_RichTextBlock" }, new object[] { new RoleList(), "_RoleList" }, new object[] { new SideMenu(), "_SideMenu" }, diff --git a/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs b/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs index fc5ac3e9..00221a3f 100644 --- a/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs +++ b/Childrens-Social-Care-CPD/Contentful/EntityResolver.cs @@ -27,6 +27,7 @@ public Type Resolve(string contentTypeId) "imageCard" => typeof(ImageCard), "linkCard" => typeof(LinkCard), "linkListCard" => typeof(LinkListCard), + "resource" => typeof(Resource), "richTextBlock" => typeof(RichTextBlock), "roleList" => typeof(RoleList), "sideMenu" => typeof(SideMenu), diff --git a/Childrens-Social-Care-CPD/Contentful/Models/Resource.cs b/Childrens-Social-Care-CPD/Contentful/Models/Resource.cs new file mode 100644 index 00000000..5e7ba1ef --- /dev/null +++ b/Childrens-Social-Care-CPD/Contentful/Models/Resource.cs @@ -0,0 +1,15 @@ +using Contentful.Core.Models; + +namespace Childrens_Social_Care_CPD.Contentful.Models; + +public class Resource : IContent +{ + public string Id { get; set; } + public string PreHeading { get; set; } + public string Heading { get; set; } + public string Summary { get; set; } + public string ResourceListSummary { get; set; } + public string From { get; set; } + public string ResourceType { get; set; } + public List ResourceItems { get; set; } +} diff --git a/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs b/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs index 0544032c..40745c8c 100644 --- a/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs +++ b/Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs @@ -26,6 +26,7 @@ public static string GetPartialFor(IContent item) case (ImageCard): return "_ImageCard"; case (LinkCard): return "_LinkCard"; case (LinkListCard): return "_LinkListCard"; + case (Resource): return "_Resource"; case (RichTextBlock): return "_RichTextBlock"; case (RoleList): return "_RoleList"; case (SideMenu): return "_SideMenu"; diff --git a/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml index 072850e2..0ca54d9e 100644 --- a/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml +++ b/Childrens-Social-Care-CPD/Views/Shared/_ErrorLayout.cshtml @@ -79,7 +79,7 @@
  • - + Resources
    +
    + @Model.PreHeading +

    @Model.Heading

    +
    +
    + +
    +
    + @{ +
      +
    • + From: @Model.From +
    • +
    • + Resource Type: : @Model.ResourceType +
    • +
    + + ContextModel model = (ContextModel)ViewBag.ContextModel; + // We use the content stack to track circular dependencies and prevent overflows + model.ContentStack.Push(Model.Id); + + if (Model.ResourceItems != null) + { + foreach (var item in Model.ResourceItems) + { + var preventOverflow = item as Content; + if (preventOverflow != null && model.ContentStack.Contains(preventOverflow.Id)) + { + + continue; + } + + await Html.RenderContentfulPartialAsync(item); + } + } + + model.ContentStack.Pop(); + } +
    +