Last active
December 20, 2017 17:04
-
-
Save justsayantan/817cb3b1c4a78d264e163f120879cbad to your computer and use it in GitHub Desktop.
Component Link in Page Metadata for DXA
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
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; } | |
} | |
} | |
} |
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
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