in Repository
public IConferenceHero GetHero()
{
var currentItem = RenderingContext.Current.Rendering.Item;
if (currentItem == null || !currentItem.IsDerived(Templates.ConferenceHero.ID))
return null;
IConference glassConfItem = _context.Cast<IConference>(currentItem?.GetAncestorOrSelfOfTemplate(Templates.Conference.ID));
IConferenceHero result = _context.Cast<IConferenceHero>(currentItem);
result.DisplayRegistrationButton = (DateTime.Today.Date > glassConfItem.LastRegistrationDate && (_registrationModel != null && !_registrationModel.IsPaid)) ? false : true;
return result;
}
in Extensions:
public static Item GetAncestorOrSelfOfTemplate(this Item item, ID templateID)
{
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
return item.IsDerived(templateID) ? item : item.Axes.GetAncestors().LastOrDefault(i => i.IsDerived(templateID));
}
No comments:
Post a Comment