Skip to content

Instantly share code, notes, and snippets.

@justsayantan
Last active December 20, 2017 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justsayantan/817cb3b1c4a78d264e163f120879cbad to your computer and use it in GitHub Desktop.
Save justsayantan/817cb3b1c4a78d264e163f120879cbad to your computer and use it in GitHub Desktop.
Component Link in Page Metadata for DXA
using System.Globalization;
using Sdl.Web.Common.Models;
namespace Models
{
public class PageViewModel : PageModel
{
private SecurityMessage message;
Provide provider = new Provider();
public PageViewModel(string id) : base(id)
{
}
[SemanticProperty(PropertyName = "securityMessage")]
public SecurityMessage SecurityMessage { get; set; }
public bool HasSecurityMessage => SecurityMessage != null;
public SecurityMessage Message
{
get
{
if (HasSecurityMessage)
{
SecurityMessage model = provider.GetSecurityMessage(SecurityMessage.Id);
return model;
}
return message;
}
set { message = value; }
}
}
}
namespace Providers
{
public class Provider
{
#region Veriable
private IContentProvider _contentProvider;
#endregion
#region Properties
protected IContentProvider ContentProvider
{
get { return _contentProvider ?? (_contentProvider = SiteConfiguration.ContentProvider); }
set { _contentProvider = value; }
}
/// <summary>
/// Read and Return the Security message
/// </summary>
/// <param name="securityMessageId"></param>
/// <returns></returns>
public SecurityMessage GetSecurityMessage(string securityMessageId)
{
try
{
string presentationId = securityMessageId + "-" + SiteLabelConfiguration.TcmUriOfDynamicTemplateForMetadata;
SecurityMessage model = ContentProvider.GetEntityModel(presentationId, WebRequestContext.Localization) as SecurityMessage;
return model;
}
catch (Exception ex)
{
throw new DxaException("Error while Gettng Dynamic Tile Component", ex);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment