Error executing template "Designs/ColoursAndCoating_generated/Paragraph/PoiUserDetails.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_72332ee423d74a1eb04ccfcbb79ad89b.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, 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.RunCompile(IRazorEngineService service, String name, 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 RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String templateSource, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @using System.Xml.Linq; 3 @using Dynamicweb; 4 @using Dynamicweb.Content.Items; 5 @using Dynamicweb.Configuration; 6 @using Dynamicweb.Security.UserManagement; 7 @using Dynamicweb.Ecommerce.International; 8 @using Bluedesk.DynamicWeb.ItemTypes.Poi; 9 @using Bluedesk.Tools.DynamicWeb.ExtensionMethods; 10 @using GeoCoordinatePortable 11 12 13 @{ 14 PoiUserDetails _data = ItemManager.Storage.GetById<PoiUserDetails>(Pageview.CurrentParagraph.ItemId ?? "0"); 15 var googlemapsAPI = Pageview.Area.Item["FrontendGoogleMapsApiKey"]?.ToString() ?? ""; 16 var countryService = Dynamicweb.Ecommerce.Services.Countries; 17 18 string markerIcon = _data.MarkerIcon; 19 int mapZoom = _data.Zoom; 20 bool disableDefaultUI = _data.disableDefaultUI; 21 bool enableZoomControl = _data.enableZoomControl; 22 23 string userId = Dynamicweb.Context.Current.Request.QueryString.Get("User") != null ? Dynamicweb.Context.Current.Request.QueryString.Get("User") : ""; 24 User poiUser = !string.IsNullOrWhiteSpace(userId) ? Dynamicweb.Security.UserManagement.User.GetUserByID(int.Parse(userId)) : null; 25 bool isPoiGroup = poiUser != null ? poiUser.Groups.Any(g => g.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_POI_Group").Value.ToString() == "True") : false; 26 27 if (poiUser != null && !string.IsNullOrWhiteSpace(poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_name").Value.ToString())) 28 { 29 poiUser.Name = poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_name").Value.ToString(); 30 } 31 if (poiUser != null && !string.IsNullOrWhiteSpace(poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_address").Value.ToString())) 32 { 33 poiUser.Address = poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_address").Value.ToString(); 34 } 35 if (poiUser != null && !string.IsNullOrWhiteSpace(poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_number").Value.ToString())) 36 { 37 poiUser.HouseNumber = poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_number").Value.ToString(); 38 } 39 if (poiUser != null && !string.IsNullOrWhiteSpace(poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_zipcode").Value.ToString())) 40 { 41 poiUser.Zip = poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_zipcode").Value.ToString(); 42 } 43 if (poiUser != null && !string.IsNullOrWhiteSpace(poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_city").Value.ToString())) 44 { 45 poiUser.City = poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_city").Value.ToString(); 46 } 47 if (poiUser != null && !string.IsNullOrWhiteSpace(poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Poi_locator_zipcode").Value.ToString())) 48 { 49 GeoCoordinate alternativeGeoLocation = GetGeoLocationByAdress($"{poiUser.Address} {poiUser.HouseNumber} {poiUser.Zip} { poiUser.City}"); 50 poiUser.GeolocationLatitude = alternativeGeoLocation.Latitude; 51 poiUser.GeolocationLongitude = alternativeGeoLocation.Longitude; 52 } 53 54 if(poiUser != null) { 55 if(!string.IsNullOrWhiteSpace(Pageview.Page.MetaTitle)) { 56 Pageview.Meta.Title = Pageview.Page.MetaTitle.Replace("{0}", poiUser.Name); 57 } else { 58 Pageview.Meta.Title = $"{Pageview.Page.MenuText} - {poiUser.Name}"; 59 } 60 } 61 62 string geolocationLatitude = poiUser.GeolocationLatitude.ToString().Replace(",", "."); 63 string geolocationLongitude = poiUser.GeolocationLongitude.ToString().Replace(",", "."); 64 65 } 66 67 <div> 68 69 @SnippetStart("GoogleMapsScript") 70 @if(!string.IsNullOrWhiteSpace(googlemapsAPI)) 71 { 72 <script src="https://maps.googleapis.com/maps/api/js?key=@googlemapsAPI"></script> 73 } 74 @SnippetEnd("GoogleMapsScript") 75 76 <div class="userpoidetail"> 77 @if(poiUser != null && isPoiGroup) 78 { 79 string userDescription = poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Description").Value.ToString(); 80 string userWebsite = poiUser.CustomFieldValues.FirstOrDefault(c => c.CustomField.SystemName == "AccessUser_Website").Value.ToString(); 81 string countryName = !string.IsNullOrWhiteSpace(poiUser.Country) ? countryService.GetCountry(poiUser.Country) != null ? countryService.GetCountry(poiUser.Country).GetName(Pageview.Area.EcomLanguageId) : poiUser.Country : poiUser.Country; 82 83 <div class="container userpoidetail__row"> 84 <section class="userpoidetail__info"> 85 <h1 class="userpoidetail__name">@poiUser.Name</h1> 86 87 @if(!string.IsNullOrWhiteSpace(userDescription)) 88 { 89 <div class="userpoidetail__description"> 90 <p>@userDescription</p> 91 </div> 92 } 93 94 <div class="userpoidetail__address"> 95 <h3>@Translate("UserDetailPoi.Address", "Address")</h3> 96 <p>@poiUser.Address @poiUser.HouseNumber</p> 97 <p>@poiUser.Zip @poiUser.City</p> 98 <p>@countryName</p> 99 </div> 100 101 <div class="userpoidetail__contact"> 102 <h3>@Translate("UserDetailPoi.Contact", "Contact")</h3> 103 @if(!string.IsNullOrWhiteSpace(poiUser.Email)) 104 { 105 <p><strong>@Translate("UserDetailPoi.Email", "Email:")</strong> <a href="mailto:@poiUser.Email">@poiUser.Email</a></p> 106 } 107 @if(!string.IsNullOrWhiteSpace(poiUser.Phone)) 108 { 109 <p><strong>@Translate("UserDetailPoi.Phone", "Phone:")</strong> <a href="tel:@poiUser.Phone">@poiUser.Phone</a></p> 110 } 111 @if(!string.IsNullOrWhiteSpace(userWebsite)) 112 { 113 <p><strong>@Translate("UserDetailPoi.Website", "Website"):</strong> <a href="@userWebsite">@userWebsite</a></p> 114 } 115 </div> 116 </section> 117 <section class="userpoidetail__map"> 118 <div id="map-@userId" data-latitude="@geolocationLatitude" data-longitude="@poiUser.GeolocationLongitude" data-markericon="@markerIcon" data-zoom="@mapZoom" data-disableui="@disableDefaultUI" data-enablezoom="@enableZoomControl" class="poi-map"></div> 119 </section> 120 </div> 121 } 122 </div> 123 </div> 124 125 @functions { 126 private static GeoCoordinate GetGeoLocationByAdress(string address) 127 { 128 // Get Google Maps API key from Settings > Control Panel > Maps 129 // Geocoding API needs to be activated for API key 130 var googlemapsAPI = SystemConfiguration.Instance.GetValue("/Globalsettings/Settings/GoogleMaps/GoogleMapsAPIKey"); 131 132 if (!string.IsNullOrWhiteSpace(googlemapsAPI)) 133 { 134 var geoxml = XDocument.Load("https://maps.google.com/maps/api/geocode/xml" + "?address=" + System.Net.WebUtility.UrlEncode(address) + "&sensor=false&key=" + googlemapsAPI); 135 136 if (geoxml.Descendants("result").Descendants("geometry").Descendants("location").Any()) 137 { 138 // Use LINQ to XML to extract the geocode values from the returned XML 139 var location = from part in geoxml.Descendants("result").Descendants("geometry").First().Descendants("location") 140 select new 141 { 142 lat = part.Element("lat").Value, 143 lng = part.Element("lng").Value 144 }; 145 146 if (location.Count() > 0) 147 { 148 double _lat = Double.Parse(location.First().lat, System.Globalization.CultureInfo.InvariantCulture); 149 double _lng = Double.Parse(location.First().lng, System.Globalization.CultureInfo.InvariantCulture); 150 var geo = new GeoCoordinate(_lat, _lng); 151 return geo; 152 } 153 } 154 } 155 156 return null; 157 } 158 } 159

subheader

See all our locations

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut viverra luctus quam, quis volutpat turpis mattis sed. Aenean volutpat sem eget sem convallis, eu facilisis orci blandit. In at libero dui. Duis turpis ipsum, facilisis non nulla et, sagittis sollicitudin turpis. Aenean nulla turpis, interdum ut massa vitae, scelerisque egestas nibh. In posuere, metus sit amet placerat rhoncus, odio felis vulputate nisl, ac venenatis arcu quam non sapien. 

Naar boven