Exception in template (Maps/templates/master-maps-v2.cshtml): System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.bdeddefdffdcfbcde.Execute()
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
at Dynamicweb.Rendering.Template.Output()
@inherits Dynamicweb.Rendering.RazorTemplateBase< Dynamicweb.Rendering.RazorTemplateModel< Dynamicweb.Rendering.Template > >
@using System.Web;
@using Dynamicweb.Modules.UserManagement;
@using Newtonsoft.Json;
@using System.Linq;
@using Dynamicweb.Querying
@functions{
public bool isWorkshopOpen( DateTime from, DateTime to )
{
return ( from != DateTime.MinValue && to != DateTime.MinValue && from.TimeOfDay.Hours > 0 );
}
public DateTime getDateTimeFromDictionary( Dictionary<string, object> dictionary, string key )
{
DateTime result = DateTime.MinValue;
if ( dictionary.ContainsKey( key ) == true && dictionary[ key ] != null )
{
DateTime? dateTime = dictionary[ key ] as DateTime?;
if ( dateTime.HasValue )
{
result = dateTime.Value;
}
}
return result;
}
public string getStringFromDictionary( Dictionary<string, object> dictionary, string key )
{
string result = "null";
if ( dictionary.ContainsKey( key ) == true && dictionary[ key ] != null )
{
result = dictionary[ key ].ToString();
}
return result;
}
public string formatWorkshopOpeningHours( DateTime time )
{
return time.ToString( "HH:mm" );
}
}
@{
string q = HttpContext.Current.Request.QueryString[ "q" ];
string countryCode = GetGlobalValue( "Global:Area.Culture.CountryCode" );
string workshopId = GetGlobalValue( "FTZ.Master.CurrentWorkshop.ID" );
string workshopName = GetGlobalValue( "FTZ.Master.CurrentWorkshop.Name" );
bool isSetWorkshopId = !string.IsNullOrEmpty( workshopId ) ? true : false;
Dictionary<string, string> daysOfWeek = new Dictionary< string, string >();
daysOfWeek[ "Monday" ] = "Mandag";
daysOfWeek[ "Tuesday" ] = "Tirsdag";
daysOfWeek[ "Wednesday" ] = "Onsdag";
daysOfWeek[ "Thursday" ] = "Torsdag";
daysOfWeek[ "Friday" ] = "Fredag";
daysOfWeek[ "Saturday" ] = "Lørdag";
daysOfWeek[ "Sunday" ] = "Søndag";
IQueryService queryService = Dynamicweb.Extensibility.ServiceLocator.Current.GetInstance< IQueryService >();
Dictionary< string, object > parameters = new Dictionary< string, object >();
List< int > groupId = new List< Int32 >();
foreach ( LoopItem group in GetLoop( "UserGroups" ) )
{
groupId.Add( group.GetInteger( "ID" ) );
}
if ( groupId.Any() )
{
parameters.Add( "groupId", groupId.ToArray() );
}
if ( string.IsNullOrEmpty( q ) == false )
{
q = q.Trim();
parameters.Add( "q", q );
}
QuerySettings querySettings = new QuerySettings
{
Parameters = parameters,
Skip = 0,
Take = int.MaxValue
};
IQueryResult result = queryService.Query( queryService.LoadQuery( "Users", "Workshops.query" ), querySettings );
dynamic json = new
{
// q = q,
// groupId = groupId,
users = new List< dynamic >()
};
foreach ( Dictionary< string, object > item in result.QueryResult )
{
@* foreach ( KeyValuePair< string, object > keyValuePair in item ) *@
@* { *@
@* <p> *@
@* @if ( keyValuePair.Key != null ) *@
@* { *@
@* @keyValuePair.Key *@
@* } *@
@* <b>==</b> *@
@* @if ( keyValuePair.Value != null ) *@
@* { *@
@* @keyValuePair.Value.ToString() *@
@* *@
@* <em> @keyValuePair.Value.GetType().ToString() </em> *@
@* } *@
@* </p> *@
@* } *@
@* <hr> *@
object id = getStringFromDictionary( item, "UserID" );
string number = getStringFromDictionary( item, "AccessUserCustomerNumber");
string name = getStringFromDictionary( item, "Name");
string username = getStringFromDictionary( item, "UserName");
string lat = getStringFromDictionary( item, "AccessUserGeoLocationLat");
string lng = getStringFromDictionary( item, "AccessUserGeoLocationLng");
string phone = getStringFromDictionary( item, "Phone");
string mail = getStringFromDictionary( item, "UserEmail");
string website = getStringFromDictionary( item, "AccessUser_UserWebsite");
// string company = getStringFromDictionary( item, "Company"); // Missing
string department = getStringFromDictionary( item, "Department");
string vatRegNumber = getStringFromDictionary( item, "AccessUserVatRegNumber");
string address = getStringFromDictionary( item, "Address");
string address2 = getStringFromDictionary( item, "Address2");
string zip = getStringFromDictionary( item, "Zip");
string city = getStringFromDictionary( item, "City");
string country = getStringFromDictionary( item, "Country");
// string countryCode = getStringFromDictionary( item, "CountryCode"); // Missing, set a global countryCode and use for all users
string departmentId = getStringFromDictionary( item, "AccessUser_ftzdepartmentid");
string workshopInternalId = getStringFromDictionary( item, "AccessUser_workshopinternalid");
string plusCustomerNumber = getStringFromDictionary( item, "AccessUser_FTZPlusCustomerNumber"); // Kay and value is null on some users.
bool isTestWorkShop = getStringFromDictionary( item, "AccessUser_TestWorkShop").ToLower() == "true";
List< dynamic > openingHours = new List< dynamic >();
foreach ( KeyValuePair< string, string > day in daysOfWeek )
{
openingHours.Add( new
{
day = day.Value,
openFrom = formatWorkshopOpeningHours( getDateTimeFromDictionary( item, day.Key + "From" ) ),
openTo = formatWorkshopOpeningHours( getDateTimeFromDictionary( item, day.Key + "To" ) ),
isOpen = isWorkshopOpen( getDateTimeFromDictionary( item, day.Key + "From" ), getDateTimeFromDictionary( item, day.Key + "To" ) )
} );
}
bool isSelected = ( isSetWorkshopId && workshopId == number );
json.users.Add( new
{
id = id,
number = number,
name = name,
department = department,
vatRegNumber = vatRegNumber,
lat = lat,
lng = lng,
address = address,
address2 = address2,
zip = zip,
city = city,
country = country,
countryCode = countryCode,
phone = phone,
mail = mail,
website = website.Contains("http") ? website : String.Format("http://{0}", website),
openingHours = openingHours,
isSelected = isSelected
} );
}
}
<div data-require-script="dealersearch_v2" class="js-e-dealersearch js-maps-api-key" data-id="@GetString( "ElementID" )" data-countrycode="@countryCode" data-unitsystem="metric" data-key="@GetString("GoogleMapsAPIKey")">
<div class="row-fluid">
<div class="span12">
<form action="" class="e-dealersearch-form js-e-dealersearch-form">
<div class="e-dealersearch-input-group">
<fieldset class="module-workshop-lookup form-input--large js-module-workshop-lookup">
<input type="text" class="required input-xlarge module-workshop-lookup-input js-e-dealersearch-input" name="" value="" placeholder="@Translate( "Dealersearch - Search field - Label", "Street, city or postal code" )" autocomplete="off">
<a href="" class="module-workshop-lookup-button js-e-dealersearch-submit-btn">
<i class="material-icons">search</i>
@Translate( "Dealersearch - Seacrh - Button", "Search" )
</a>
<script id="js-e-handlebars-tmpl-typeahead-pending" type="text/x-handlebars-template">
<div class="js-e-dealersearch-geolocate js-e-dealersearch-suggestions-item e-dealersearch-suggestions-item-geolocation dropdown-item tt-selectable"><i class="material-icons material-icons-large">my_location</i> @Translate( "Dealersearch - Your location - Text", "My location" )</div>
</script>
<script id="js-e-handlebars-tmpl-typeahead-footer" type="text/x-handlebars-template">
<div class="js-e-dealersearch-geolocate js-e-dealersearch-suggestions-item e-dealersearch-suggestions-item-geolocation dropdown-item tt-selectable"><i class="material-icons material-icons-large">my_location</i> @Translate( "Dealersearch - Your location - Text", "My location" )</div>
</script>
</fieldset>
</div>
</form>
</div>
</div>
<div class="row-fluid">
<div class="span12 mega">
<div class="e-dealersearch-googlemap-container js-e-dealersearch-googlemap-container">
<div class="e-embed-container text-branded e-dealersearch-googlemap js-e-dealersearch-googlemap"> </div>
<script>
var masterData = masterData || {};
masterData['@GetString( "ElementID" )'] = @JsonConvert.SerializeObject( json );
</script>
<script id="js-e-handlebars-tmpl-googlemap-infowindow" type="text/x-handlebars-template">
<div class="e-dealersearch-googlemap-infowindow e-maps-infowindow">
<h3>{{department}}</h3>
<p>
{{address}}<br>
{{zip}} {{city}}
</p>
<p>
<i class="material-icons"></i>
@Translate( "Modules_Maps_Label_Phone", "Tlf.", "global" )
{{phone}}
<br>
<a class="plain" href="mailto:{{{mail}}}">
<i class="material-icons"></i>
{{mail}}
</a>
<br>
<a class="plain" href="{{{website}}}">
<i class="material-icons"></i>
@Translate( "Modules_Maps_Label_Website", "Besøg hjemmeside", "global" )
</a>
</p>
<br>
<p>
CVR: {{vatRegNumber}}
</p>
{{#unless isSelected}}
<a href="#" class="maps-map-set-workshop-button js-maps-set-workshop" data-workshop-name="{{department}}" data-workshop-id="{{number}}">
<i class="material-icons">check</i>
@Translate( "Maps_Search_Set_Workshop", "Vælg værksted" )
</a>
{{/unless}}
</div>
</script>
</div>
</div>
</div>
<br>
<div class="row-fluid">
<div class="span12">
<div class="js-e-dealersearch-list">
<script id="js-e-handlebars-tmpl-marker-list" type="text/x-handlebars-template">
<ul id="js-e-map-list" class="e-map-list" data-workshop-id="@workshopId" data-device-mobile="@GetString( "Global:Device.IsMobile" )">
{{#each markers}}
<li class="e-map-list-item webshop-map-search-dealer js-e-dealersearch-list-item {{#if isSelected}}user-workshop-selected{{/if}}" data-dealer-id="{{id}}" data-id="{{id}}" data-dealer-name="{{department}}" data-workshop-id="{{number}}">
<h3 class="js-e-dealersearch-list-item-show-on-map">
<small class="e-map-list-item-distance js-e-map-list-item-distance"></small>
<div class="js-e-map-list-dealer-name">
{{department}}
</div>
</h3>
{{#if isSelected}}
<a href="#" class="maps-set-workshop-button button-selected" data-workshop-name="{{department}}" data-workshop-id="{{number}}">
<i class="material-icons">check</i>
</a>
{{else}}
<a href="#" class="maps-set-workshop-button js-maps-set-workshop" data-workshop-name="{{department}}" data-workshop-id="{{number}}">
<i class="material-icons">done</i>
</a>
{{/if}}
<p class="address js-e-dealersearch-list-item-show-on-map">
{{#if address2}}{{address2}}<br>{{/if}}
{{zip}} {{city}}
</p>
<p>
{{#if phone}}
<br>
<i class="material-icons"></i>
@Translate( "Modules_Maps_Label_Phone", "Tlf.", "global" )
@if ( GetString( "Global:Device.IsMobile" ) == "True" )
{
<a href="tel:{{{phone}}}">
{{phone}}
</a>
}
else
{
@:{{phone}}
}
{{/if}}
{{#if mail}}
<br>
<a class="plain" href="mailto:{{{mail}}}">
<i class="material-icons"></i>
{{{mail}}}
</a>
{{/if}}
<br>
<a class="plain" target="_blank" href="{{{website}}}">
<i class="material-icons"></i>
@Translate( "Modules_Maps_Label_Website", "Besøg hjemmeside", "global" )
</a>
</p>
<br>
<h5>@Translate( "Modules_Maps_Label_OpeningHours", "Åbningstider", "global" ):</h5>
<table class="table table-condensed">
{{#each openingHours}}
<tr class="{{#unless isOpen}}closed{{/unless}}">
<td style="width: 35%;">{{day}}</td>
<td>{{#if isOpen}}{{openFrom}} - {{openTo}}{{else}}lukket{{/if}}</td>
</tr>
{{/each}}
</table>
{{#if name}}
<strong>
@Translate( "Modules_Maps_Label_Indehaver", "Indehaver", "global" ):
{{name}}
</strong>
<br>
<span>CVR: {{vatRegNumber}}</span>
{{/if}}
</li>
{{/each}}
</ul>
</script>
</div>
</div>
</div>
</div>