Error executing template "Designs/Grundsalg/_parsed/areas.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at RKSK.Api.GroundSaleUtility.GetCitiesFromParcels(Object parcels)
   at CompiledRazorTemplates.Dynamic.RazorEngine_b7dc6eb63e5647798a749e236907cf46.Execute() in E:\dynamicweb.net\Solutions\rksk.net.dynamicweb-cms.com\Website\Files\Templates\Designs\Grundsalg\_parsed\areas.parsed.cshtml:line 207
   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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 2 @using System; 3 @using System.Web; 4 @using System.Linq; 5 @using Dynamicweb.Rendering; 6 7 8 @{ 9 bool isCommercialArea = GetGlobalValue("Global:Page.Top.ID") == "20101"; 10 string logoLink = isCommercialArea ? "/Default.aspx?ID=20101" : "/Default.aspx?ID=14315"; 11 bool gisActive = RKSK.Api.GroundSaleUtility.ServiceActive("https://gisext.rksk.dk/arcgis/rest/services/Temaer/MapServer/2/query?f=pjson"); 12 if (!gisActive) 13 { 14 string htmlError = "<div style='padding: 10px; font-size: 20px; font-weight:bold;'>Der er problemer med at indhente boliger lige nu. Vi arbejder p&aring; sagen!<br>Pr&oslash;v igen om 5 minutter.<p>"; 15 HttpContext.Current.Response.Flush(); 16 HttpContext.Current.Response.Write(htmlError); 17 HttpContext.Current.Response.End(); 18 } 19 } 20 21 @using System.IO; 22 @using System.Web; 23 24 @functions { 25 string GetImageUrl(string url, int width = 200, int height = 200){ 26 if (string.IsNullOrWhiteSpace(url)){ 27 url = string.Format("http://placehold.it/{0}x{1}", width, height); 28 } 29 else 30 { 31 url = url.Replace("http://rksk.dk", ""); 32 url = url.Replace("https://rksk.dk", ""); 33 } 34 35 if (!url.StartsWith("http://")){ 36 url = string.Format("/Admin/Public/GetImage.ashx?Image={0}&width={1}&height={2}", url, width, height); 37 } 38 return url; 39 } 40 41 42 string GetRandomImage(string path){ 43 44 string file = ""; 45 if (!string.IsNullOrEmpty(path)){ 46 var extensions = new string[] { ".png", ".jpg", ".gif" }; 47 try{ 48 var di = new DirectoryInfo(HttpContext.Current.Request.MapPath(path)); 49 50 var rgFiles = di.GetFiles("*.*").Where( f => extensions.Contains( f.Extension.ToLower())); 51 Random R = new Random(); 52 file = rgFiles.ElementAt(R.Next(0,rgFiles.Count())).FullName; 53 } 54 catch {} 55 } 56 57 string replace_file_root = System.Web.HttpContext.Current.Server.MapPath("/files"); 58 string file_replaced_root = file.Replace(replace_file_root, "/Files"); 59 60 string replace_slash = @"\"; 61 string file_replaced = file_replaced_root.Replace(replace_slash, "/"); 62 63 return file_replaced; 64 } 65 66 string GetTopImagePath(int pageid){ 67 68 string folder = "Borger"; 69 switch (pageid){ 70 case 74: 71 folder = "Erhverv"; 72 break; 73 case 76: 74 folder = "OmKommunen"; 75 break; 76 } 77 78 return folder; 79 } 80 81 } 82 83 <!DOCTYPE html> 84 <html lang="da"> 85 <head> 86 <meta http-equiv="content-type" content="text/xhtml; charset=utf-8"> 87 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> 88 89 @if (HttpContext.Current.Request.Url.Host.Contains(".rksk.vjm.dk")) 90 { 91 <meta name="robots" content="noindex,nofollow"> 92 } 93 94 <title>@GetValue("Title")</title> 95 @GetValue("MetaTags") 96 @GetValue("CopyRightNotice") 97 98 99 100 <script id="CookieConsent" src="https://policy.app.cookieinformation.com/uc.js" data-culture="DA" type="text/javascript"></script> 101 102 <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'> 103 <link href='https://fonts.googleapis.com/css?family=Bitter:400,700' rel='stylesheet' type='text/css'> 104 <link href='/Files/Templates/Designs/Grundsalg/css/styles.css?v=2' rel='stylesheet' type='text/css'> 105 <link href="/Files/Templates/Designs/rksk/favicon.ico" type="image/x-icon" rel="icon"> 106 <link href="/Files/Templates/Designs/rksk/favicon.ico" type="image/x-icon" rel="shortcut icon"> 107 108 @RenderSnippet("Links") 109 @RenderSnippet("Metas") 110 111 <!--[if lt IE 9]> 112 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script> 113 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.3.0/respond.js"></script> 114 <![endif]--> 115 116 @GetValue("Stylesheets") 117 @GetValue("Javascripts") 118 </head> 119 <body> 120 121 <nav class="nav--jump" aria-label="Genveje til indhold" title="Genveje til indhold"> 122 <ul> 123 <li> 124 <a href="#leftMenu" title="Spring til sidens menu" accesskey="1" class=""> 125 Navigation 126 </a> 127 </li> 128 <li> 129 <a href="#Indhold" title="Spring til indhold på siden" accesskey="2" class=""> 130 Indhold 131 </a> 132 </li> 133 </ul> 134 </nav> 135 136 <div class="site--topbar clearfix"> 137 <div class="container"> 138 <nav class="nav nav--topbar clearfix" aria-label="Privat eller erhverv grundsalg genveje"> 139 <ul> 140 <li><a href="/" title="Gå til privat grundsalg" class="@if(!isCommercialArea) { <text>active</text> }">Boliggrunde</a></li> 141 <li><a href="/erhverv" title="Gå til erhverv grundsalg" class="@if(isCommercialArea) { <text>active</text> }">Erhvervsgrunde</a></li> 142 </ul> 143 </nav> 144 </div> 145 </div> 146 147 <header class="site--header"> 148 <section class="container" aria-label="logo og hovednavigation"> 149 150 <a href="@logoLink" title="Gå til forside" aria-label="Logo desktop/tablet" class="site--logo hidden-xs hidden-sm"> 151 <img src="/Files/Templates/Designs/Grundsalg/img/logo_naturens_rige.png" alt="Logo Ringkøbing Skjern Kommune"> 152 </a> 153 154 155 <a href="@logoLink" title="Gå til forside" aria-label="Logo mobil" class="site--logo site--logo-mobile visible-xs visible-sm"> 156 <img src="/Files/Templates/Designs/Grundsalg/img/logo_stripped.png" alt="Logo Ringkøbing Skjern Kommune" width="50px"> 157 </a> 158 159 <div class="visible-xs visible-sm"> 160 <a id="DropdownMenu" class="nav-button" href="#"> 161 <span class="nav-button-icon">&#9776; Menu</span> 162 </a> 163 </div> 164 165 <nav aria-label="Hoved menu"> 166 @if (isCommercialArea) 167 { 168 @GetValue("DwNavigation(MainNavigationErhverv)") 169 } 170 else 171 { 172 @GetValue("DwNavigation(MainNavigation)") 173 174 } 175 </nav> 176 </section> 177 </header> 178 179 <div role="main" aria-label="Sidens indhold"> 180 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 181 @using System; 182 @using System.Web; 183 @using System.Data; 184 @using Dynamicweb.Data; 185 @using Dynamicweb.Rendering; 186 187 188 189 @{ 190 //get all areas 191 string areaType = isCommercialArea ? "erhverv" : "bolig"; 192 193 int groundTypeCode = 1; 194 string plotBaseGisUrl = "https://gisext.rksk.dk/arcgis/rest/services/Temaer/MapServer/2"; 195 string whereGisArea = @"where=""Paa_web""=%27JA%27"; 196 if (areaType == "erhverv") 197 { 198 groundTypeCode = 4; 199 plotBaseGisUrl = "https://gisext.rksk.dk/arcgis/rest/services/Temaer/MapServer/3"; 200 whereGisArea = @"where=""Paa_web_erhverv""=%27JA%27"; 201 } 202 203 string urlGisArea = String.Format("https://gisext.rksk.dk/arcgis/rest/services/GISext_registrering/MapServer/18/query?{0}&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=25832&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=25832&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&resultOffset=&resultRecordCount=&f=pjson", whereGisArea); 204 dynamic areasJson = RKSK.Api.GroundSaleUtility.GetJson(urlGisArea); 205 206 //get cities from parcels 207 List<string> cities = RKSK.Api.GroundSaleUtility.GetCitiesFromParcels(areasJson); 208 209 //get plots 210 string whereGisPlots = @"where=%22grund_type_kode%22="+ groundTypeCode + "%20and%20ADRESSE+is+not+Null%20and%20STATUS_SALG=%27Ledig%27"; 211 if (!String.IsNullOrEmpty(HttpContext.Current.Request["parcel"])) 212 { 213 whereGisPlots = whereGisPlots + String.Format("%20and%20Omraadenr=%27{0}%27", HttpContext.Current.Request["parcel"].ToString()); 214 } 215 string urlGisPlots = String.Format(plotBaseGisUrl + "/query?{0}&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=25832&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=25832&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&resultOffset=&resultRecordCount=&f=pjson", whereGisPlots); 216 dynamic plotsJson = RKSK.Api.GroundSaleUtility.GetJson(urlGisPlots); 217 } 218 219 @helper formtypeactive(string type) 220 { 221 if (!String.IsNullOrEmpty(HttpContext.Current.Request["type"])) 222 { 223 if (type == HttpContext.Current.Request["type"].ToString()) 224 { 225 <text>selected</text> 226 } 227 } 228 } 229 230 <div class="container" id="Indhold"> 231 <div class="row"> 232 <div class="col-xs-12"> 233 <h1>Alle grunde</h1> 234 <p>Vælg et område og find lige netop den grund, du vil vide mere om.</p> 235 236 237 <div class="plot__area__filter"> 238 <form class="form form-horizontal" method="get"> 239 <div class="row"> 240 <div class="col-md-4"> 241 <label for="parcel">Udstykning:</label> 242 <select class="form-control" name="parcel" id="parcel"> 243 <option value="">--Vælg udstykning--</option> 244 @{ 245 foreach (string city in cities) 246 { 247 <text> 248 <optgroup label="@city"> 249 </optgroup></text> 250 251 foreach (var features in areasJson.features) 252 { 253 if (features.attributes != null && city == features.attributes.Bynavn.ToString()) 254 { 255 string selected = ""; 256 if (!String.IsNullOrEmpty(HttpContext.Current.Request["parcel"])) 257 { 258 if (HttpContext.Current.Request["parcel"].ToString() == features.attributes.Omraadenr.ToString()) 259 { 260 selected = "selected='selected'"; 261 } 262 } 263 <option value="@features.attributes.Omraadenr" @selected="">@features.attributes.Omraade_navn</option> 264 } 265 } 266 267 <text> 268 </text> 269 } 270 } 271 </select> 272 </div> 273 274 <div class="col-md-4 hidden"> 275 <label for="type">Type:</label> 276 <select class="form-control" name="type" id="type"> 277 <option value="">--Vælg type--</option> 278 <option value="1" @formtypeactive("1")="">Private grunde</option> 279 <!-- 280 <option value="erhverv">Erhvers grunde</option> 281 <option value="byggeri">Byggerier</option> 282 --> 283 284 </select> 285 </div> 286 <div class="col-md-4"> 287 <button type="submit" class="btn btn-primary">Find grunde</button> 288 </div> 289 </div> 290 </form> 291 </div> 292 293 <div class="plot__frontpage__plots__item__container"> 294 <div class="row"> 295 @{ 296 using (IDbConnection connection = Database.CreateConnection()) 297 { 298 IDbCommand commandNext = connection.CreateCommand(); 299 commandNext.CommandText = @"SELECT Page.PageMenuText, Page.PageID, ItemType_Template__GrundsalgGrund.Omraadenr 300 FROM ItemType_Template__GrundsalgGrund 301 INNER JOIN Page ON ItemType_Template__GrundsalgGrund.Id = Page.PageItemId 302 WHERE Page.PageItemType = 'Template__GrundsalgGrund' 303 ORDER BY Page.PageParentPageID"; 304 System.Data.IDataReader newestIDataReader = commandNext.ExecuteReader(); 305 306 while (newestIDataReader.Read()) 307 { 308 string areaNumber = newestIDataReader["Omraadenr"].ToString(); 309 string pageName = newestIDataReader["PageMenuText"].ToString(); 310 int pageId = Dynamicweb.Core.Converter.ToInt32(newestIDataReader["PageID"]); 311 string[] pageNameArr = pageName.Split(','); 312 313 string town = pageNameArr[0].Trim(); 314 string address = pageNameArr[1].Trim(); 315 316 //get attributes for plot 317 dynamic plotJsonAttributes = null; 318 foreach (var features in plotsJson.features) 319 { 320 if (features.attributes != null) 321 { 322 if (areaNumber == features.attributes.Omraadenr.ToString() && address == features.attributes.ADRESSE.ToString()) 323 { 324 plotJsonAttributes = features.attributes; 325 break; 326 } 327 } 328 } 329 330 //get attributes for area 331 dynamic areaJsonAttributes = null; 332 foreach (var features in areasJson.features) 333 { 334 if (features.attributes != null) 335 { 336 if (areaNumber == features.attributes.Omraadenr.ToString()) 337 { 338 areaJsonAttributes = features.attributes; 339 break; 340 } 341 } 342 } 343 344 if (plotJsonAttributes == null || areaJsonAttributes == null) 345 { 346 continue; 347 } 348 349 string photoUrl = plotJsonAttributes.Foto_1.ToString(); 350 photoUrl = photoUrl.Replace("https://grundsalg.rksk.dk", ""); 351 photoUrl = photoUrl.Replace("http://grundsalg.rksk.dk", ""); 352 353 string photo = String.Empty; 354 if (String.IsNullOrEmpty(photoUrl)) 355 { 356 photo = "/Files/Templates/Designs/Grundsalg/img/not-found.jpg"; 357 } 358 else 359 { 360 photo = GetImageUrl(photoUrl, 300, 200); 361 } 362 363 decimal buildingArea = RKSK.Api.GroundSaleUtility.CalculateBuildingArea(plotJsonAttributes.grundareal.ToString()); 364 365 <div class="col-md-4"> 366 <a href="/Default.aspx?ID=@pageId" title="Gå til: @address"> 367 <div class="plot__frontpage__plots__item"> 368 369 <div class="plot__frontpage__plots__item__image__wrapper"> 370 <img src="@photo" class="plot__frontpage__plots__item__image img-responsive"> 371 <div class="icon plot__frontpage__plots__item__image__share hidden-xs hidden-sm" aria-hidden="true">&#xf064;</div> 372 </div> 373 <div class="plot__frontpage__plots__item__content"> 374 <p class="plot__frontpage__plots__item__content__road">@address</p> 375 <p class="plot__frontpage__plots__item__content__zip">@areaJsonAttributes.Postnr, @town</p> 376 <p class="plot__frontpage__plots__item__content__price">kr. @String.Format("{0:#,##0.##}", Dynamicweb.Core.Converter.ToInt32(plotJsonAttributes.pris))</p> 377 </div> 378 <div class="clearfix"> 379 <div class="plot__frontpage__plots__item__bottom"> 380 <div class="plot__frontpage__plots__item__bottom__boxes"> 381 <p>Grundareal</p> 382 <p>@plotJsonAttributes.grundareal &nbsp;</p> 383 </div> 384 <div class="plot__frontpage__plots__item__bottom__boxes"> 385 <p>Bygningsareal</p> 386 <p> 387 @if (buildingArea == 0) 388 { 389 <text>-</text> 390 } 391 else 392 { 393 @buildingArea 394 } 395 &nbsp; 396 </p> 397 </div> 398 <div class="plot__frontpage__plots__item__bottom__boxes"> 399 <p>Pris pr. kvm.</p> 400 <p>@plotJsonAttributes.kvm_pris &nbsp;</p> 401 </div> 402 </div> 403 </div> 404 </div> 405 </a> 406 </div> 407 } 408 } 409 } 410 </div> 411 </div> 412 </div> 413 </div> 414 </div> 415 416 417 </div> 418 419 <footer class="site--footer-container"> 420 <section class="site--footer" aria-label="Kontakt og åbningstider"> 421 422 <div class="container"> 423 424 <div class="row"> 425 <div class="col-sm-4 col-xs-12"> 426 <div class="site--footer-content-container"> 427 <div class="row"> 428 <div class="site--footer-content col-md-12"> 429 @RenderParagraphContent(18971) 430 </div> 431 </div> 432 </div> 433 </div> 434 435 <div class="col-sm-4 col-xs-12"> 436 <div class="site--footer-content-container"> 437 <div class="row"> 438 <div class="site--footer-content col-md-12"> 439 @RenderParagraphContent(18972) 440 </div> 441 </div> 442 </div> 443 </div> 444 445 <div class="col-sm-4 col-xs-12"> 446 <div class="site--footer-content-container"> 447 <div class="row"> 448 <div class="site--footer-content col-md-12"> 449 @RenderParagraphContent(18973) 450 </div> 451 </div> 452 </div> 453 </div> 454 455 <div class="row"> 456 <div class="col-xs-12"> 457 <a href="https://www.rksk.dk/om-kommunen/organisation/databeskyttelse#accordion-8" title="Se privatlivspolitik gældende for www.rksk.dk og dens subdomæner" target="_blank">Privatlivspolitik gældende for www.rksk.dk og dens subdomæner</a><br> 458 <a href="https://www.rksk.dk/om-kommunen/organisation/databeskyttelse#accordion-7" title="Se kommunes cookiepolitik for www.rksk.dk og dens subdomæner" target="_blank">Kommunes cookiepolitik for www.rksk.dk og dens subdomæner</a> 459 </div> 460 </div> 461 </div> 462 463 </div> 464 465 </section> 466 </footer> 467 468 469 470 <div class="modal fade" id="sectionTypeModal" role="dialog" aria-labelledby="sectionTypeModalLabel" aria-modal="true" aria-hidden="true" tabindex="-1"> 471 <div class="modal-dialog"> 472 <div class="modal-content"> 473 <div class="site__sectiontype__container"> 474 <div class="h1" id="sectionTypeModalLabel"> 475 @GetString("Item.Area.ModalSectionTypeHeader") 476 </div> 477 <div class="site__sectiontype__content"> 478 @GetString("Item.Area.ModalSectionTypeContent") 479 </div> 480 <div class="site__sectiontype__buttons"> 481 <div class="row"> 482 <div class="col-sm-6"> 483 <a href="/" class="btn btn-block btn-primary" title="Gå til boliggrunde">Boliggrunde</a> 484 </div> 485 <div class="col-sm-6"> 486 <a href="/Default.aspx?ID=20101" class="btn btn-block site__sectiontype__buttons--blue" title="Gå til erhvervsgrunde">Erhvervsgrunde</a> 487 </div> 488 </div> 489 </div> 490 </div> 491 </div> 492 </div> 493 </div> 494 495 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 496 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> 497 <script type="text/javascript" src="/Files/Templates/Designs/Grundsalg/js/scripts.min.js?v=2"></script> 498 499 @RenderSnippet("JavaScript") 500 501 <script> 502 // INLINE SCRIPT FOR AT SIKRE OS AT REPONSIVE BREDDER OVERHOLDES PÅ WINDOWS PHONE. 503 // http://getbootstrap.com/getting-started/#support-ie10-width 504 if (navigator.userAgent.match(/IEMobile\/10\.0/)) { 505 var msViewportStyle = document.createElement("style") 506 msViewportStyle.appendChild( 507 document.createTextNode( 508 "&#64;-ms-viewport{width:auto!important}" 509 ) 510 ) 511 document.getElementsByTagName("head")[0].appendChild(msViewportStyle) 512 } 513 </script> 514 515 <script type="text/javascript"> 516 window.addEventListener('CookieInformationConsentGiven', function (event) { 517 if (CookieInformation.getConsentGivenFor('cookie_cat_statistic')) { 518 /*<![CDATA[*/ 519 (function () { 520 var sz = document.createElement('script'); sz.type = 'text/javascript'; sz.async = true; 521 sz.src = '//siteimproveanalytics.com/js/siteanalyze_2542.js'; 522 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(sz, s); 523 })(); 524 /*]]>*/ 525 } 526 }, false); 527 </script> 528 </body> 529 </html></div>