Error executing template "Designs/Swift/Paragraph/COMM_InstructorSummary.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Ecommerce.ProductCatalog.ProductViewModelExtensions.GetProductLink(ProductViewModel product, Int32 pageId, Boolean usePrimaryGroupPageId)
at CompiledRazorTemplates.Dynamic.RazorEngine_0a33382a5f0c4dc4a4d82e3bbc71aa6f.<>c__DisplayClass3_0.<RenderBody>b0(TextWriter razor_helper_writer) in C:\inetpub\wwwroot\directions2023_uat\Files\Templates\Designs\Swift\Paragraph\COMM_InstructorSummary.cshtml:line 144
at CompiledRazorTemplates.Dynamic.RazorEngine_0a33382a5f0c4dc4a4d82e3bbc71aa6f.Execute() in C:\inetpub\wwwroot\directions2023_uat\Files\Templates\Designs\Swift\Paragraph\COMM_InstructorSummary.cshtml:line 139
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using Dynamicweb.Ecommerce.ProductCatalog
@using Dynamicweb.Frontend
@functions{
public class ProductInstructor
{
public string instructorName {get; set;}
public string instructorDescription {get; set;}
public string instructorLinkedInLink {get; set;}
public string instructorImage {get; set;}
public string instructorLink {get; set;}
public string productPrice {get; set;}
public string productSubtitle {get; set;}
public string productStaticPrice {get; set;}
public string productCurrency {get; set;}
public string productCategory {get; set;}
public string eventCode {get; set;}
}
static string GetFileExtensionUsingSplit(string filePath)
{
// Use Split to get the file name and then Split again to get the extension
string[] parts = filePath.Split('/');
string fileName = parts[parts.Length - 1];
string[] fileNameParts = fileName.Split('.');
string extension = fileNameParts.Length > 1 ? fileNameParts[fileNameParts.Length - 1] : string.Empty;
return extension;
}
ProductViewModel product = null;
}
@{
if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
{
product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
}
else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode)
{
var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page);
ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel();
if (productList?.Products is object)
{
product = productList.Products[0];
}
}
ProductInstructor instructor = new ProductInstructor();
string eventCode = "";
if (product is object) {
string selectedDisplayGroup = "Instructor";
IEnumerable<string> selectedDisplayGroupIds = selectedDisplayGroup.Split(',').ToList();
List<CategoryFieldViewModel> displayGroups = new List<CategoryFieldViewModel>();
foreach (var selection in selectedDisplayGroupIds)
{
foreach (CategoryFieldViewModel group in product.FieldDisplayGroups.Values)
{
if (selection == group.Id)
{
foreach (var field in group.Fields)
{
string fieldSystemName = field.Value.SystemName;
var fieldValue = field.Value.Value;
switch(fieldSystemName)
{
case "PersonLink":
instructor.instructorLink = fieldValue.ToString();
break;
case "PersonDescription":
instructor.instructorDescription = fieldValue.ToString();
break;
case "PersonImage":
instructor.instructorImage = fieldValue.ToString();
break;
case "PersonName":
instructor.instructorName = fieldValue.ToString();
break;
case "PersonLinkedIn":
instructor.instructorLinkedInLink = fieldValue.ToString();
break;
case "EventCode":
instructor.eventCode = fieldValue.ToString();
break;
case "ProductPrice":
instructor.productPrice = fieldValue.ToString();
break;
case "ProductSubtitle":
instructor.productSubtitle = fieldValue.ToString();
break;
case "ProductStaticPrice":
instructor.productStaticPrice = fieldValue.ToString();
break;
case "ProductCurrency":
instructor.productCurrency = fieldValue.ToString();
break;
case "ItemCategory":
instructor.productCategory = fieldValue.ToString();
break;
}
}
}
}
}
}
}
@{
string layout = Model.Item.GetRawValueString("Layout", "text-start");
layout = layout == "alignLeft" ? "align-items-start text-start" : layout;
layout = layout == "alignCenter" ? "align-items-center text-center" : layout;
layout = layout == "alignRight" ? "align-items-end text-end" : layout;
layout = layout == "alignLeftMiddle" ? "align-items-start text-start justify-content-center" : layout;
string contentPadding = Model.Item.GetRawValueString("ContentPadding", "");
contentPadding = contentPadding == "none" ? "p-0" : contentPadding;
contentPadding = contentPadding == "small" ? "p-3 p-md-3" : contentPadding;
contentPadding = contentPadding == "large" ? "p-5 p-md-5" : contentPadding;
string maxWidth = Model.Item.GetRawValueString("TextReadability", "max-width-on");
maxWidth = maxWidth == "max-width-on" ? " mw-75ch" : maxWidth;
maxWidth = maxWidth == "max-width-off" ? " w-100" : maxWidth; @* CUSTOM CODE *@
string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) && Model.Item.GetRawValueString("Theme") != "no-theme" ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
}
<style>
.item_swift_productheader{
min-height:80px;
}
</style>
<div class="h-100 position-relative d-flex flex-column mb-0-last-child @contentPadding @(layout)@(theme) item_@Model.Item.SystemName.ToLower()">
<a name="@Model.ID" class="user-select-none position-absolute top-0" style="scroll-margin-top:var(--header-height,150px)"></a>
@{@RenderBody(maxWidth, instructor)}
</div>
@helper RenderBody(string maxWidth, ProductInstructor instructor)
{
string link = product.GetProductLink(GetPageIdByNavigationTag("Shop"), false);
Dynamicweb.Frontend.LinkViewModel link1 = new Dynamicweb.Frontend.LinkViewModel();
Dynamicweb.Frontend.LinkViewModel link2 = new Dynamicweb.Frontend.LinkViewModel();
int ticketsPageId = GetPageIdByNavigationTag("Tickets");
int sponsorshipPageId = GetPageIdByNavigationTag("Sponsorships");
//string ticketsEventCode = Model.Item.GetString("Ticket_Event_Code");
//string sponsorshipEventCode = Model.Item.GetString("Sponsorship_Event_Code");
//ticketsEventCode = ticketsEventCode != "" ? ticketsEventCode : parentEventCode;
//sponsorshipEventCode = sponsorshipEventCode != "" ? sponsorshipEventCode : parentEventCode;
string buyLink = "Default.aspx?ID=";
buyLink = instructor.productCategory == "SPONSOR" || instructor.productCategory == "S-RELATED" ? buyLink + sponsorshipPageId : buyLink + ticketsPageId;
buyLink = instructor.eventCode != "" ? buyLink + "&eventCode=" + instructor.eventCode : buyLink;
@*if(linkType1 == "buy-tickets")
{
LinkViewModel ticketsLink = new LinkViewModel();
ticketsLink.IsExternal = false;
ticketsLink.Url = "/Default.aspx?ID=" + ticketsPageId;
ticketsLink.Url = ticketsEventCode != "" ? ticketsLink.Url + "&EventCode=" + ticketsEventCode : ticketsLink.Url;
link1 = ticketsLink;
}
if(linkType1 == "buy-sponsorship")
{
LinkViewModel sponsorshipLink = new LinkViewModel();
sponsorshipLink.IsExternal = false;
sponsorshipLink.Url = "/Default.aspx?ID=" + sponsorshipPageId;
sponsorshipLink.Url = sponsorshipEventCode != "" ? sponsorshipLink.Url + "&EventCode=" + sponsorshipEventCode : sponsorshipLink.Url;
link1 = sponsorshipLink;
}
*@
@*if (!string.IsNullOrEmpty(instructor.productSubtitle))
{
string titleColor = "text-inherit";
string titleOpacity = "opacity-100";
string titleFontSize = "h4";
string headingLevel = "h2";
string headingLevelStart = $"<{headingLevel} class=\"{titleFontSize} {titleColor} {titleOpacity}{maxWidth} mb-3\">";
string headingLevelStop = $"</{headingLevel}>";
@headingLevelStart
@instructor.productSubtitle
@headingLevelStop
}*@
@*if (!string.IsNullOrEmpty(instructor.instructorName))
{
string subtitleColor = "text-inherit";
string subtitleOpacity = "opacity-100";
string subtitleFontSize = "fs-6";
<p class="@subtitleFontSize @subtitleColor @subtitleOpacity mb-3@(maxWidth)">
<strong>@(Translate("Instructor") + ": " + instructor.instructorName)</strong>
</p>
}*@
string productStaticPrice = instructor.productStaticPrice != "" ? instructor.productStaticPrice : instructor.productPrice + " " + instructor.productCurrency;
if (!string.IsNullOrEmpty(productStaticPrice))
{
string titleColor = "text-inherit";
string titleOpacity = "opacity-100";
string titleFontSize = "h4";
string headingLevel = "h4";
string headingLevelStart = $"<{headingLevel} class=\"{titleFontSize} {titleColor} {titleOpacity}{maxWidth} mb-3\">";
string headingLevelStop = $"</{headingLevel}>";
@headingLevelStart
@(Translate("Price")+":"+ productStaticPrice)
@headingLevelStop
}
if (!string.IsNullOrEmpty(Model.Item.GetString("Title")) && !Model.Item.GetBoolean("HideTitle"))
{
string titleColor = "text-inherit";
string titleOpacity = "opacity-100";
string titleFontSize = "h5";
string headingLevel = "h5";
string headingLevelStart = $"<{headingLevel} class=\"{titleFontSize} {titleColor} {titleOpacity}{maxWidth} mb-3\">";
string headingLevelStop = $"</{headingLevel}>";
@headingLevelStart
@Model.Item.GetString("Title")
@headingLevelStop
}
<div class="py-2" data-col-size="12">
<div class="d-flex flex-row w-100 mb-2">
<div class="input-group input-primary-button-group flex-nowrap">
<a href="@buyLink" class="btn btn-primary btn-sm" style="white-space: nowrap" title="Translate("Add to cart")" id="AddToCartButton@product.Id">
<span class="text-nowrap d-flex align-items-center justify-content-center gap-2">
<span class="icon-2"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-shopping-cart"><circle cx="9" cy="21" r="1"></circle><circle cx="20" cy="21" r="1"></circle><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path></svg></span> <span class="d-none d-md-inline">@Translate("Buy this product")</span><span class="d-inline d-md-none">@Translate("Buy")</span>
</span>
</a>
</div>
</div>
<div class="d-flex flex-row w-100">
<div class="input-group input-primary-button-group flex-nowrap">
<a href="@link" class="btn btn-secondary btn-sm" style="white-space: nowrap" title="@Translate("More details")" id="ViewButton@product.Id">
<span class="text-nowrap d-flex align-items-center justify-content-center gap-2">
<span class="d-none d-md-inline">@Translate("More details")</span><span class="d-inline d-md-none">@Translate("More details")</span>
</span>
</a>
</div>
</div>
</div>
}
@helper RenderImage(ProductInstructor instructor)
{
FileViewModel image = new FileViewModel();
image.Extension = GetFileExtensionUsingSplit(instructor.instructorImage);
image.Name = instructor.instructorName;
image.Path = instructor.instructorImage;
image.FocalY = 0;
image.FocalX = 0;
if (!string.IsNullOrEmpty(instructor.instructorImage))
{
int xPos = 50;
int yPos = 50;
string ratioCssClass = string.Empty;//Model.Item.GetRawValueString("ImageAspectRatio") != "0" && Model.Item.GetRawValueString("ImageAspectRatio") != "" ? "ratio" : string.Empty;
string ratioVariable = string.Empty;//Model.Item.GetRawValueString("ImageAspectRatio") != "0" && Model.Item.GetRawValueString("ImageAspectRatio") != "" ? "style=\"--bs-aspect-ratio: " + Model.Item.GetRawValueString("ImageAspectRatio") + "\"" : string.Empty;
string imageAspect = string.Empty;//Model.Item.GetRawValueString("ImageAspectRatio", string.Empty);
string ImageObjectFit = string.Empty;//Model.Item.GetRawValueString("ImageObjectFit", string.Empty);
ImageObjectFit = ImageObjectFit == "cover" ? string.Empty : ImageObjectFit;
ImageObjectFit = ImageObjectFit == "contain" ? "object-fit:contain" : ImageObjectFit;
var parms = new Dictionary<string, object>();
parms.Add("loading", "lazy");
parms.Add("style", ImageObjectFit);
parms.Add("alt", instructor.instructorName);
parms.Add("columns", 1);
//parms.Add("cssClass", "rounded-7"); @* CUSTOM CODE *@
parms.Add("fullwidth", true);
parms.Add("cssClass", "img-fluid");
<figure>
@RenderPartial("../Components/Image.cshtml", image ?? new Dynamicweb.Frontend.FileViewModel(), parms)
</figure>
}
}