Error executing template "Designs/kultursamarbejdet/QueryPublisher/kultur-search.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_4e8bb3f1157f4a4eb5ac94843a23caea.Execute() in D:\dynamicweb.net\Solutions\holstebrokommune.espresso4.dk\files\Templates\Designs\kultursamarbejdet\QueryPublisher\kultur-search.cshtml:line 90
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 @using System
2 @using System.Collections.Generic
3 @using System.Web;
4 @using System.Text.RegularExpressions
5 @using Co3.Espresso.Website.Services
6 @using Dynamicweb.Frontend
7 @using Co3.HK.Dw.Services
8 @inherits Co3.Espresso.Website.TemplateBases.Pages.PageBase
9 @using System.Globalization;
10 @using System.Text.RegularExpressions;
11 @using Dynamicweb.Ecommerce.Common;
12 @using Co3.Espresso.Website.Services;
13 @using System.Web;
14
15 @functions {
16 CultureInfo AreaCultureInfo = Dynamicweb.Frontend.PageView.Current().Area.CultureInfo;
17
18 public string getProductLink( string groupID, string productID, string variantID = "" ) {
19 string result = string.Empty;
20 string displayPage = ProductService.Instance.GetGroupDisplayPage( groupID );
21 if( string.IsNullOrEmpty( displayPage ) == false ) {
22 if( string.IsNullOrEmpty( variantID ) == false ) {
23 result = "{0}&ProductID={1}&variantID={2}";
24 result = string.Format( result, displayPage, productID, variantID );
25 }
26 else {
27 result = "{0}&ProductID={1}";
28 result = string.Format( result, displayPage, productID );
29 }
30 }
31 return result;
32 }
33
34 public bool isProductGroupPublishedOnWebsite( string groupID ) {
35 bool result = false;
36 string displayPage = ProductService.Instance.GetGroupDisplayPage( groupID );
37 if( string.IsNullOrEmpty( displayPage ) == false ) {
38 result = true;
39 }
40 return result;
41 }
42
43 public string getNewsLink( string categoryName, string newsID ) {
44 string result = NewsService.Instance.GetNewsDisplayPage( categoryName, newsID );
45 string displayPage = NewsService.Instance.GetNewsDisplayPage( categoryName, newsID );
46 if( string.IsNullOrEmpty( displayPage ) == false ) {
47 result = "/" + displayPage.Replace( "Id", "ID" ).Replace( "#", "&PID=" ) + "&M=NewsV2&Action=1&NewsID=" + newsID +"&NId=" + newsID +"&NewsCategory="+HttpContext.Current.Server.UrlEncode(categoryName);
48 //result = SearchEngineFriendlyURLs.GetFriendlyUrl( result );
49 }
50 return result;
51 }
52
53 public string getImageURL( string url, int width = 2560, int height = 0, int crop = 0, int Compression = 95, string format = "jpg", string donotupscale = "True" ) {
54 string result = string.Empty;
55 if( string.IsNullOrEmpty( url ) == false ) {
56 result = "/admin/public/getimage.ashx?Image={0}&Width={1}&Height={2}&Format={3}&Compression={4}&Crop={5}&DoNotUpscale={6}";
57 result = string.Format( result, url, width, height, format, Compression, crop, donotupscale );
58 }
59 return result;
60 }
61
62 public string getPriceFormatted( string price ) {
63 string result = string.Empty;
64 if( string.IsNullOrEmpty( price ) == true ) {
65 price = Context.Currency.Format(0.00, false);
66 }
67 if ( Context.Currency.SymbolPlace == 0 ) {
68 result = string.Format( "<span class=\"e-product-price-symbol\">{1}</span> {0}", price, Context.Currency.Symbol );
69 }
70 else{
71 result = string.Format( "{0} <span class=\"e-product-price-symbol\">{1}</span>", price, Context.Currency.Code );
72 }
73 return result;
74 }
75
76 public string getShortDate( DateTime date ) {
77 string result = string.Empty;
78 result = date.Date.ToString( AreaCultureInfo.DateTimeFormat.ShortDatePattern ).Replace( "-" , "." );
79 return result;
80 }
81
82 public string getLongDate( DateTime date ) {
83 string result = string.Empty;
84 result = date.Date.ToString( AreaCultureInfo.DateTimeFormat.LongDatePattern );
85 return result;
86 }
87 }
88
89 @{
90 string searchQuery = HttpContext.Current.Request[ "q" ].Trim();
91 string searchItemType = !string.IsNullOrEmpty( HttpContext.Current.Request[ "type" ] ) ? HttpContext.Current.Request[ "type" ].Trim() : string.Empty;
92 string searchPattern = String.Format( "({0})", searchQuery );
93 string replacePattern = "<span class='text-primary'>$1</span>";
94 DateTime dateTimeNow = DateTime.Now;
95 int websideCount = 0;
96 int nyhedCount = 0;
97 int medarbejderCount = 0;
98 int jobsCount = 0;
99 int resultCount = GetLoop( "QueryResultItem" ).Count( r => r.GetString( "Type" ) != "" );
100 string qSearchTerm = "";
101
102 foreach ( LoopItem queryParam in GetLoop( "Query.Parameters" ) )
103 {
104 if ( queryParam.GetString("Parameter.Name") == "q" )
105 {
106 qSearchTerm = queryParam.GetString( "Parameter.Value" );
107 }
108 }
109
110 <div class="e-search js-e-search" data-test="@qSearchTerm">
111 <div class="">
112
113 @if ( string.IsNullOrEmpty( qSearchTerm ) )
114 {
115 <div class="row">
116 <div class="col-12 col-md-12 col-lg-9 col-xl-9">
117 <h1 class="text-center">Ingen resultater</h1>
118 </div>
119 </div>
120 }
121 else
122 {
123
124 <div class="row">
125
126 <div class="col-12">
127 <div class="js-e-search-result-pages e-search-result-pages mb-3">
128 <div class="row">
129
130 @{
131 string[] searchTypes = { "Webside", "Nyhed", "Medarbejder", "Jobs" };
132 }
133
134 @foreach ( string searchType in searchTypes )
135 {
136 foreach ( LoopItem result in GetLoop( "QueryResultItem" ).Where( r => r.GetString( "Type" ).Equals( searchType ) ).OrderByDescending( r => r.GetInteger( "SearchWeight" ) ) )
137 {
138 int id = result.GetInteger( "Id" );
139 string url = string.Empty;
140 string title = result.GetString( "Title" );
141 string facetGroup = result.GetString( "Type" );
142 string image = result.GetString( "Image" );
143 string date = getLongDate( result.GetDate( "Date" ) );
144 string categoryName = result.GetString( "CategoryName" );
145 string employeeId = result.GetString( "EmployeeId" );
146 string employeeName = result.GetString( "EmployeeName" );
147 string employeeEmail = result.GetString( "EmployeeEmail" );
148 string employeeEmail2 = result.GetString( "EmployeeEmail2" );
149 bool mailExists = !string.IsNullOrEmpty( employeeEmail );
150 string employeePhone = result.GetString( "EmployeePhone" );
151 string employeeTitle = result.GetString( "EmployeeTitle" );
152 string employeeDepartment = result.GetString( "EmployeeDepartment" );
153 string employeeCompany = result.GetString( "EmployeeCompany" );
154 int searchWeight = result.GetInteger( "SearchWeight" );
155 int typeCount = GetLoop( "QueryResultItem" ).Count( t => t.GetString( "Type" ).Equals( facetGroup ) );
156
157 if ( string.IsNullOrEmpty( title ) == true )
158 {
159 title = result.GetString( "Name" );
160 }
161 string text = result.GetString( "Text" );
162 string pageMetaDescription = result.GetString( "PageMetaDescription" );
163
164
165 string resultType = result.GetString( "EspressoField_Type" );
166 if ( resultType == "Page" )
167 {
168 url = DynamicwebBugFixService.Instance.GetFriendlyUrl( id );
169 }
170 else if ( resultType == "News" )
171 {
172 url = getNewsLink( result.GetString( "CategoryName" ), id.ToString() );
173 }
174 if ( string.IsNullOrEmpty( title ) != true )
175 {
176 title = Regex.Replace( title, searchPattern, replacePattern, RegexOptions.IgnoreCase );
177 }
178 if ( string.IsNullOrEmpty( text ) != true )
179 {
180 text = text.Substring( 0, Math.Min( text.Length, 175 ) );
181 text = Regex.Replace( text, searchPattern, replacePattern, RegexOptions.IgnoreCase );
182 }
183 if ( string.IsNullOrEmpty( pageMetaDescription ) != true )
184 {
185 pageMetaDescription = pageMetaDescription.Substring( 0, Math.Min( pageMetaDescription.Length, 175 ) );
186 pageMetaDescription = Regex.Replace( pageMetaDescription, searchPattern, replacePattern, RegexOptions.IgnoreCase );
187 }
188 if ( !string.IsNullOrEmpty( facetGroup ) )
189 {
190 if ( string.IsNullOrEmpty( url ) == false && ( facetGroup == searchItemType || string.IsNullOrEmpty( searchItemType ) ) )
191 {
192
193 if ( facetGroup == "Webside" )
194 {
195 if ( websideCount == 0 )
196 {
197 <div class="col-12">
198 <h1>
199 <span class="js-e-search-result-count">@resultCount</span> @Translate( "Search - Result Count - Text", "results" )
200 </h1>
201 </div>
202 }
203 <div class="col-12 col-md-10 offset-md-2 col-lg-8 offset-lg-4 mb-2 hk-search-webpage-item js-hk-search-webpage-item @*@( websideCount > 5 ? "d-none" : "" )*@" data-count="@websideCount">
204 <p class="mb-1"><small><a href="@url">@url</a></small></p>
205 <h2 class="mt-0 mb-0"><a href="@url">@title</a></h2>
206 <p class="mt-1 mb-1">@text...</p>
207 <p>
208 <a class="btn btn-secondary" href="@url">Læs mere</a>
209 </p>
210 </div>
211 websideCount++;
212 }
213
214 if ( facetGroup == "Nyhed" )
215 {
216 if ( nyhedCount == 0 )
217 {
218 <div class="col-12">
219 <h2 class="pb-2">Nyheder<img src="/Files/Images/icons/edit/hk-custom-newspaper.svg" alt=""></h2></div>
220 }
221 <div class="col-12 col-md-12 col-lg-6 col-xl-4 hk-search-news-item js-hk-search-news-item @( nyhedCount > 8 ? "d-none" : "" )" data-count="@nyhedCount">
222 <span class="img-container" test="@image">
223 @if ( image.Contains( "http" ) )
224 {
225 <img src="@image" alt="" />
226 }
227 else
228 {
229 <img src="/admin/public/getimage.ashx?Image=/Files/Images/@image&Width=600&Format=jpg&Quality=75&Crop=3/" alt="" />
230 }
231 <span class="date-text">@date</span>
232 </span>
233 <div class="news-tags-container">
234 <span>@categoryName</span>
235 </div>
236 <h3 class="mb-1 mt-1">@title</h3>
237 <p class="small"><small>@(text)...</small></p>
238 <a href="@url" class="hk-search-news-link" title="@title"></a>
239 </div>
240 if ( nyhedCount == 8 )
241 {
242 <div class="col-12 text-center">
243 <a href class="js-hk-search-news-item-show-more hk-custom-search-expand">Se flere nyheder <i class="material-icons">keyboard_arrow_down</i></a>
244 </div>
245 }
246 nyhedCount++;
247 if ( typeCount == nyhedCount )
248 {
249 <div class="col-12 mb-1"><hr></div>
250 }
251 }
252
253 if ( facetGroup == "Medarbejder" )
254 {
255 if ( medarbejderCount == 0 )
256 {
257 <div class="col-12">
258 <h2 class="pb-2">Medarbejdere <img src="/Files/Images/icons/edit/hk-custom-account-group-circle.svg" alt=""></h2></div>
259 }
260 <div class="col-12 col-md-6 col-lg-4 col-xl-3 hk-search-employee-item js-hk-search-employee-item mb-1 @( medarbejderCount > 11 ? "d-none" : "" )" data-count="@medarbejderCount">
261 <div class="employee-wrapper">
262 <h3 class="mb-0">@employeeName</h3>
263 <p class="small">@employeeTitle</p>
264 <p class="small">@employeeDepartment</p>
265 @if ( mailExists )
266 {
267 <a href="mailto:@employeeEmail"><i class="material-icons">mail_outline</i>Send email</a><br>
268 }
269 <a href="tel:@employeePhone"><i class="material-icons">phone</i>@employeePhone</a>
270 </div>
271 </div>
272 if ( medarbejderCount == 11 )
273 {
274 <div class="col-12 text-center">
275 <a href class="js-hk-search-employee-item-show-more hk-custom-search-expand">Se flere medarbejdere <i class="material-icons">keyboard_arrow_down</i></a>
276 </div>
277 }
278 medarbejderCount++;
279 if ( typeCount == medarbejderCount )
280 {
281 <div class="col-12 mb-1"><hr></div>
282 }
283 }
284
285 if ( facetGroup == "Jobs" )
286 {
287 if ( jobsCount == 0 )
288 {
289 <div class="col-12">
290 <h2 class="pb-2">Jobs <img src="/Files/Images/icons/edit/hk-custom-find-job.svg" alt=""></h2></div>
291 }
292 <div class="col-12 col-md-12 col-lg-6 hk-search-job-item js-hk-search-job-item mb-2 @( jobsCount > 5 ? "d-none" : "" )" data-count="@jobsCount">
293 <h3 class="mb-1"><a href="@url">@title</a></h3>
294 <p class="small mb-0">@(text)...</p>
295 </div>
296 if ( jobsCount == 5 )
297 {
298 <div class="col-12 text-center">
299 <a href class="js-hk-search-job-item-show-more hk-custom-search-expand">Se flere jobs <i class="material-icons">keyboard_arrow_down</i></a>
300 </div>
301 }
302 jobsCount++;
303 if ( typeCount == jobsCount )
304 {
305 <div class="col-12 mb-1"><hr></div>
306 }
307 }
308
309 }
310 }
311 }
312 }
313 </div>
314 </div>
315 </div>
316 </div>
317
318 <div class="js-e-search-loading-overlay e-loading-overlay e-search-loading-overlay">
319 <div class="e-loading-spinner"></div>
320 </div>
321 }
322 </div>
323 </div>
324 }