Error executing template "Designs/RizzoDesignFolder/eCom/Product/Teacher.cshtml"
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at CompiledRazorTemplates.Dynamic.RazorEngine_db30b56832ff4780a87d6009ae0e8167.Execute() in E:\Dynamicweb.NET\Solutions\dw9live.juc.dk\Files\Templates\Designs\RizzoDesignFolder\eCom\Product\Teacher.cshtml:line 155
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, ITemplateSource templateSource, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 2 3 @using Dynamicweb.Rendering; 4 @using Dynamicweb.Ecommerce.Products; 5 @using System.Globalization; 6 @using Co3.JUC.Website.Models.Frontend 7 @using Co3.JUC.Website.Services 8 9 @{ 10 Dynamicweb.Content.Items.Item areaItem = Pageview.Area.Item; 11 string ecommerceLanguageID = Pageview.Area.EcomLanguageId; 12 13 bool isLoggedIn = Dynamicweb.Security.UserManagement.User.IsExtranetUserLoggedIn ( ), 14 isFrontEnd = Dynamicweb.Security.UserManagement.User.IsExtranetUserLoggedIn ( ), 15 productIsFavorite = GetBoolean("Ecom:Product.IsProductInFavoriteList"); 16 17 string currentPageId = Pageview.ID.ToString(), 18 variantDefaultId = GetString("Ecom:Product.DefaultVariantComboID"), 19 variantCurrentId = GetString("Ecom:Product.VariantID"), 20 variantId = (!string.IsNullOrEmpty(variantCurrentId)) ? variantCurrentId : variantDefaultId, 21 titleKey = "title", 22 title = "", 23 imageKey = "image", 24 image = "", 25 stockStatus = GetInteger("Ecom:Product.Stock") > 0 ? "fa-check" : "fa-close", 26 productId = GetString("Ecom:Product.ID"), 27 productLanguage = GetString("Ecom:Product.LanguageID"), 28 productName = GetString("Ecom:Product.Name"), 29 productNumber = GetString("Ecom:Product.Number"), 30 pattern = productNumber + "*", 31 productImage = ViewService.Instance.GetImagePathUrl(GetString("Ecom:Product.ImageSmall.Clean"), GetString("Ecom:Product.ImageMedium.Clean"), GetString("Ecom:Product.ImageLarge.Clean"), pattern), 32 productGetImage = ViewService.Instance.GetImage(productImage, 0, 600), 33 imagesFolder = "/Files/Files/RizzoDesignFolder/Products/", 34 imagePattern = imagesFolder + productNumber + ".jpg", 35 productIntro = GetString("Ecom:Product.ShortDescription"), 36 productDescription = GetString("Ecom:Product.LongDescription"), 37 pointPrice = GetString("Ecom:Product.PointPrice"), 38 productDetails = GetString("Ecom:Product:Field.Details.Value.Clean"), 39 productWarranty = GetString("Ecom:Product:Field.Warranty.Value.Clean"), 40 productPrice = GetString("Ecom:Product.Price"), 41 productRemoveFromList = "/Default.aspx?Id="+currentPageId+ "&amp;ProductID=" + productId +"&amp;CCRemoveFromMyLists="+productId+"&amp;CCRemoveFromListVariantID="+variantId+"&amp;CCRemoveFromListLanguageID="+productLanguage, 42 productAddToList = "/Default.aspx?Id="+currentPageId+ "&amp;ProductID=" + productId +"&amp;CCAddToMyLists="+productId+"&amp;CCAddToListVariantID="+variantId+"&amp;CCAddToListLanguageID="+productLanguage, 43 favoriteUrl = productIsFavorite ? productRemoveFromList : productAddToList, 44 // Filter for downloads item 45 downloadsFilter = "Products contains 'p_"+productId+",' or Products contains 'p_"+productId+":' or Products ends with 'p_"+productId+"'"; 46 47 List<Dictionary<string, string>> imagesList = new List<Dictionary<string, string>>(); 48 } 49 50 <div id="product-container" class="teacher-container" data-pageId="@currentPageId" data-productId="@productId" data-variantId="@variantId" data-errorCombination1='@Translate("combinationNotAvailable","Combination not available")' > 51 <article id="product-description" class="col-xs-12 noPadding"> 52 <div id="leftSide" class="col-xs-12 col-lg-8"> 53 <div> 54 <div class="smartbuttons"> 55 <a href="javascript:window.print();" id="smart_print"></a> 56 </div> 57 @if (!String.IsNullOrEmpty(productImage)) 58 { 59 <div id="product-image"> 60 <figure> 61 <img class="img-responsive" src="@productGetImage" alt="@productName" title="@productName" /> 62 </figure> 63 </div> 64 } 65 <h2>@productName</h2> 66 @if (!String.IsNullOrEmpty(productIntro) || !String.IsNullOrEmpty(productDescription)) 67 { 68 <div id="product-description"> 69 @productIntro 70 @productDescription 71 </div> 72 } 73 </div> 74 </div> 75 76 <div id="rightSide" class="col-xs-12 col-lg-4"> 77 <div> 78 @{ 79 string sql = string.Format("SELECT * FROM EcomProducts p INNER JOIN EcomProductsRelated pr ON pr.ProductRelatedProductID = p.ProductID WHERE pr.ProductRelatedProductRelID = '{0}' and p.ProductLanguageID ='{1}' and pr.ProductRelatedGroupID = 'RELGRP2'", productId, productLanguage); 80 81 var relatedProducts = Dynamicweb.Ecommerce.Services.Products.GetProductsBySql(sql); 82 83 if (relatedProducts.Any()) 84 { 85 int relatedProductsIndex = 0; 86 int productMonth = 0; 87 int productYear = 0; 88 int productDay = 0; 89 90 <div class="related-products-legend hidden-lg">@Translate("UnderviserPafolgende", "Underviser på følgende kurser/netværk")</div> 91 <div class="related-products-legend-rev hidden-md hidden-sm hidden-xs">@Translate("UnderviserPafolgende", "Underviser på følgende kurser/netværk")</div> 92 @*<div class="BoxBelow"></div>*@ 93 <ul class="related-products"> 94 @foreach (var relatedProduct in relatedProducts) 95 { 96 relatedProductsIndex++; 97 //TODO: Switch between standard datecontrol and new - DONE 98 ProductFieldValue relatedProductDay = relatedProduct.ProductFieldValues.GetProductFieldValue("Day"); 99 ProductFieldValue relatedProductMonth = relatedProduct.ProductFieldValues.GetProductFieldValue("Month"); 100 ProductFieldValue relatedProductYear = relatedProduct.ProductFieldValues.GetProductFieldValue("Year"); 101 ProductFieldValue relatedProductUseNewDateFields = relatedProduct.ProductFieldValues.GetProductFieldValue( "newDateFIelds" ); 102 103 string ShowDateOnList = relatedProduct.ProductFieldValues.GetProductFieldValue("ShowDateOnList").Value.ToString(); 104 var relatedProductLectures = relatedProduct.ProductFieldValues.GetProductFieldValue("Lectures"); 105 string relatedProductLecturesDecimal = relatedProduct.ProductFieldValues.GetProductFieldValue("LecturesDecimal").Value.ToString(); 106 107 DateTime currentDate = DateTime.Now; 108 string[] monthNames = DateTimeFormatInfo.CurrentInfo.AbbreviatedMonthNames; 109 110 string relatedProductID = relatedProduct.Id, 111 relatedProductName = relatedProduct.Name, 112 relatedProductIntro = relatedProduct.ShortDescription, 113 relatedProductText = ViewService.Instance.GetTeaserText(ViewService.Instance.StripHtml(relatedProductIntro), 80), 114 relatedProductDate = string.Format("<strong>{0}</strong><span>{1}</span>", relatedProductDay.Value.ToString(), monthNames[Convert.ToInt32(relatedProductMonth.Value.ToString()) - 1]), 115 relatedProductLink = "javascript:void(0)", 116 relatedProductPrimaryGroupID = relatedProduct.PrimaryGroupId, 117 relatedProductMod2Class = "mod"+(relatedProductsIndex % 2).ToString(), 118 relatedProductClass = "related-product-item " + relatedProductMod2Class; 119 120 121 //Hide related products if outdated 122 productDay = Convert.ToInt32(relatedProductDay.Value.ToString()); 123 productMonth = Convert.ToInt32(relatedProductMonth.Value.ToString()); 124 productYear = Convert.ToInt32(relatedProductYear.Value.ToString()); 125 126 if (relatedProductUseNewDateFields.HasValue ) 127 { 128 bool useNewDateFields = false; 129 bool.TryParse( relatedProductUseNewDateFields.Value.ToString(), out useNewDateFields ); 130 131 if ( useNewDateFields ) 132 { 133 List< ActivityDay > sortActivityDays = ActivityService.Instance.GetActivityDays( relatedProduct.Id, relatedProduct.VariantId, productLanguage ); 134 if ( sortActivityDays != null && sortActivityDays.Count > 0 ) 135 { 136 ActivityDay nextFutureActivity = sortActivityDays.OrderBy( sortAd => sortAd.StartTime ).FirstOrDefault( sortAd => sortAd.StartTime.Date >= DateTime.Today ); 137 if ( nextFutureActivity != null ) 138 { 139 productDay = nextFutureActivity.StartTime.Date.Day; 140 productMonth = nextFutureActivity.StartTime.Date.Month; 141 productYear = nextFutureActivity.StartTime.Date.Year; 142 relatedProductDate = string.Format( "<strong>{0}</strong><span>{1}</span>", productDay, monthNames[ productMonth - 1 ] ); 143 } 144 } 145 } 146 } 147 148 bool productIsActive = ViewService.Instance.IsActive(productMonth, productYear, productDay); 149 150 151 var relatedProductGroups = relatedProduct.Groups; 152 153 if (relatedProductGroups.Any()) 154 { 155 var relatedProductGroup = (!String.IsNullOrEmpty(relatedProductPrimaryGroupID)) ? relatedProductGroups.Where(x => x.Id == relatedProductPrimaryGroupID).First() : relatedProductGroups.First(); 156 157 if (!relatedProductGroup.IsTopGroup) 158 { 159 string relatedProductGroupPrimaryParentGroupID = relatedProductGroup.PrimaryParentGroupId; 160 if (relatedProductGroup.ParentGroups.Any()) 161 { 162 relatedProductGroup = (!String.IsNullOrEmpty(relatedProductGroupPrimaryParentGroupID)) ? relatedProductGroup.ParentGroups.Where(x => x.Id == relatedProductGroupPrimaryParentGroupID).First() : relatedProductGroup.ParentGroups.First(); 163 } 164 } 165 166 string relatedProductGroupPrimaryPage = relatedProductGroup.Meta.PrimaryPage.ToString(), 167 relatedProductGroupColor = relatedProductGroup.ProductGroupFieldValues.GetProductGroupFieldValue("Color").Value.ToString(); 168 169 if (!String.IsNullOrEmpty(relatedProductGroupPrimaryPage)) 170 { 171 relatedProductLink = relatedProductGroupPrimaryPage + "&productid=" + relatedProductID; 172 } 173 if (!String.IsNullOrEmpty(relatedProductGroupColor)) 174 { 175 relatedProductClass += " " + relatedProductGroupColor; 176 } 177 } 178 179 <li class="@relatedProductClass @(productIsActive ? "" : "hide")"> 180 <div> 181 <div class="related-info"> 182 <ul> 183 <li class="productDate "> 184 <div> 185 @if ( relatedProductClass.Contains( "green" ) ) 186 { 187 <strong style="text-transform: none">@Translate( "E", "e" )</strong><span>@Translate( "Learning", "Learning" )</span> 188 } 189 else 190 { 191 if ( ShowDateOnList == "False" ) 192 { 193 @relatedProductDate; 194 } 195 196 } 197 </div> 198 </li> 199 <li class="productLessons"> 200 <div> 201 <strong> 202 @if ( !String.IsNullOrEmpty(relatedProductLecturesDecimal) && (relatedProductLecturesDecimal!="0") ) 203 { 204 @relatedProductLecturesDecimal 205 } 206 else 207 { 208 @relatedProductLectures.Value 209 } 210 </strong> 211 <span>@Translate("ShortLectures", "Lekt.")</span> 212 </div> 213 </li> 214 </ul> 215 </div> 216 <div class="related-details"> 217 <h3> 218 <a href="@relatedProductLink" title="@relatedProductName"> 219 @relatedProductName 220 </a> 221 </h3> 222 @*<div> 223 <a href="@relatedProductLink" title="@relatedProductName"> 224 @relatedProductText 225 </a> 226 </div>*@ 227 </div> 228 </div> 229 <a href="@relatedProductLink" title="@relatedProductName" class="overlayLink">@relatedProductName</a> 230 </li> 231 } 232 </ul> 233 } 234 235 } 236 </div> 237 </div> 238 </article> 239 240 </div> 241 242 @SnippetStart("OGMeta") 243 <meta property="og:title" content='@productName' /> 244 <meta property="og:image" content='@Pageview.GlobalTags.GetTagByName("Global:Request.Scheme").Value.ToString()://@Pageview.GlobalTags.GetTagByName("Global:Request.Host").Value.ToString()@imagePattern' /> 245 <meta property="og:site_name" content='@areaItem["CompanyName"]' /> 246 <meta property="og:url" content='@Pageview.GlobalTags.GetTagByName("Global:Request.Scheme").Value.ToString()://@Pageview.GlobalTags.GetTagByName("Global:Request.Host").Value.ToString()@Pageview.GlobalTags.GetTagByName("Global:Pageview.Url").Value.ToString()' /> 247 <meta property="og:description" content="@ViewService.Instance.StripHtml(productIntro)" /> 248 <meta property="og:type" content="article" /> 249 <meta property="og:locale" content='@Pageview.GlobalTags.GetTagByName("Global:Area.LongLang").Value.ToString().Replace("-", "_")' /> 250 @SnippetEnd("OGMeta") 251 @SnippetStart("jsOnLoad") 252 @SnippetEnd("jsOnLoad") 253