Error executing template "Designs/Swift/TemplateRenderer/Custom__CompleteSalesPersonInfo.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_b11a8be6a8f84bf4b0af5c8b77595231.Execute() in F:\Domains\Sites\int-krvc.mydwsitec.com\Files\Templates\Designs\Swift\TemplateRenderer\Custom__CompleteSalesPersonInfo.cshtml:line 7
   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 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @using Dynamicweb.Environment 3 4 @{ 5 string apiKey = !string.IsNullOrEmpty(Pageview.AreaSettings.GetString("Google_APIKey")) ? Pageview.AreaSettings.GetString("Google_APIKey") : ""; 6 var loginUser = Dna.Extensions.Users.GetRealUser(); 7 var loginUserSsnCustomField = loginUser.CustomFieldValues.FirstOrDefault(f => f.CustomField.SystemName == Dna.Keystone.Users.Constants.UserCustomFields.Ssn); 8 var loginUserExtensionCustomField = loginUser.CustomFieldValues.FirstOrDefault(f => f.CustomField.SystemName == Dna.Keystone.Users.Constants.UserCustomFields.Extension); 9 var isLoginUserInSalesPersonRole = Dna.Keystone.Users.Helpers.IsUserInSalesPersonRole(loginUser); 10 var isFormSubmitted = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Request.Form.Get(Dna.Keystone.Users.Constants.Request.IsSalesPersonInformationForm)); 11 var isUserBlockedAfterUpdatingInformation = false; 12 if (isFormSubmitted) 13 { 14 var requestFirstName = Dynamicweb.Context.Current.Request.Form.Get("firstName"); 15 var requestLastName = Dynamicweb.Context.Current.Request.Form.Get("lastName"); 16 var requestAddress = Dynamicweb.Context.Current.Request.Form.Get("address"); 17 var requestZip = Dynamicweb.Context.Current.Request.Form.Get("zip"); 18 var requestCity = Dynamicweb.Context.Current.Request.Form.Get("city"); 19 var requestState = Dynamicweb.Context.Current.Request.Form.Get("state"); 20 var requestCountryCode = Dynamicweb.Context.Current.Request.Form.Get("countryCode"); 21 var requestSsn = Dynamicweb.Context.Current.Request.Form.Get("ssn"); 22 var requestEmail = Dynamicweb.Context.Current.Request.Form.Get("email"); 23 var requestPhone = Dynamicweb.Context.Current.Request.Form.Get("phone"); 24 var requestExtension = Dynamicweb.Context.Current.Request.Form.Get("extension"); 25 var requestFax = Dynamicweb.Context.Current.Request.Form.Get("fax"); 26 27 var isUserInformationUpdated = requestFirstName != loginUser.FirstName || requestLastName != loginUser.LastName 28 || requestAddress != loginUser.Address || requestZip != loginUser.Zip || requestCity != loginUser.City 29 || requestState != loginUser.State || requestCountryCode != loginUser.CountryCode 30 || requestEmail != loginUser.Email || requestPhone == loginUser.Phone; 31 32 loginUser.FirstName = requestFirstName; 33 loginUser.LastName = requestLastName; 34 loginUser.Address = requestAddress; 35 loginUser.Zip = requestZip; 36 loginUser.City = requestCity; 37 loginUser.State = requestState; 38 loginUser.CountryCode = requestCountryCode; 39 if (!string.IsNullOrEmpty(requestSsn) && string.IsNullOrEmpty(Dynamicweb.Core.Converter.ToString(loginUserSsnCustomField.Value))) 40 { 41 loginUserSsnCustomField.Value = requestSsn; 42 } 43 loginUser.Email = requestEmail; 44 loginUser.Phone = requestPhone; 45 if (loginUserExtensionCustomField != null) 46 { 47 loginUserExtensionCustomField.Value = requestExtension; 48 } 49 loginUser.Fax = requestFax; 50 51 loginUser.Save(); 52 53 if (isUserInformationUpdated && isLoginUserInSalesPersonRole) 54 { 55 Dna.Keystone.Users.Helpers.BlockSalesPersonUserAfterSalesPersonInformationIsUpdated(loginUser); 56 isUserBlockedAfterUpdatingInformation = true; 57 new Dynamicweb.Security.Permissions.UnifiedPermissionService().ClearUserCache(Dynamicweb.Core.Converter.ToString(loginUser.ID)); 58 new Dynamicweb.Security.Permissions.UnifiedPermissionService().ClearUserCache(Dynamicweb.Core.Converter.ToString(Pageview.User.ID)); 59 } 60 61 if (Pageview.User == loginUser) 62 { 63 var dashboardPageId = GetPageIdByNavigationTag("MyAccountDashboardPage"); 64 var dashboardPageFriendlyUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(dashboardPageId); 65 if (!string.IsNullOrEmpty(dashboardPageFriendlyUrl)) 66 { 67 Dynamicweb.Context.Current.Response.Redirect(dashboardPageFriendlyUrl); 68 } 69 } 70 } 71 72 var isLoginUserInBlockedSalesPersonRole = Dna.Keystone.Users.Helpers.IsUserInBlockedSalesPersonRole(loginUser); 73 74 string currentCountry = !string.IsNullOrEmpty(loginUser.CountryCode) ? loginUser.CountryCode : Pageview.Area.EcomCountryCode; 75 var regions = Dynamicweb.Ecommerce.Services.Countries.GetRegions(currentCountry); 76 string countrySelectorColumnSize = "g-col-12 g-col-lg-6"; 77 string regionLabel = "State"; 78 79 var loginUserSsn = Dna.Keystone.Users.Encryption.DecryptText(Dynamicweb.Core.Converter.ToString(loginUserSsnCustomField?.Value)); 80 var formSsnFieldDisabledText = string.Empty; 81 if (!string.IsNullOrEmpty(loginUserSsn) && loginUserSsn.Length > 5) 82 { 83 loginUserSsn = $"x{loginUserSsn.Substring(loginUserSsn.Length - 4)}"; 84 formSsnFieldDisabledText = "disabled"; 85 } 86 } 87 88 <header class="d-flex flex-row align-items-center gap-3 p-3 border-bottom"> 89 <h1 class="h6 m-0 flex-fill">@Translate("Sales person information")</h1> 90 </header> 91 92 @if (!Dna.Keystone.Users.Helpers.IsUserSalesPersonInformationPopulated(loginUser)) 93 { 94 <div class="alert alert-warning mt-3"> 95 <h6>@Translate("Please fill the following fields")</h6> 96 97 <ul> 98 @if (string.IsNullOrEmpty(loginUser.FirstName)) 99 { 100 <li>@Translate("First name")</li> 101 } 102 @if (string.IsNullOrEmpty(loginUser.LastName)) 103 { 104 <li>@Translate("Last name")</li> 105 } 106 @if (string.IsNullOrEmpty(loginUser.Address)) 107 { 108 <li>@Translate("Address")</li> 109 } 110 @if (string.IsNullOrEmpty(loginUser.Zip)) 111 { 112 <li>@Translate("Zip")</li> 113 } 114 @if (string.IsNullOrEmpty(loginUser.City)) 115 { 116 <li>@Translate("Town / City")</li> 117 } 118 @if (string.IsNullOrEmpty(loginUser.State)) 119 { 120 <li>@Translate("State")</li> 121 } 122 @if (string.IsNullOrEmpty(loginUser.Country)) 123 { 124 <li>@Translate("Country")</li> 125 } 126 @if (string.IsNullOrEmpty(loginUserSsn) && isLoginUserInBlockedSalesPersonRole) 127 { 128 <li>@Translate("SSN")</li> 129 } 130 @if (string.IsNullOrEmpty(loginUser.Email)) 131 { 132 <li>@Translate("Email")</li> 133 } 134 @if (string.IsNullOrEmpty(loginUser.Phone)) 135 { 136 <li>@Translate("Phone")</li> 137 } 138 </ul> 139 </div> 140 } 141 @if (isFormSubmitted) 142 { 143 <div class="alert alert-warning mt-3"> 144 <h6>@Translate("Contact information updated.")</h6> 145 </div> 146 } 147 148 @if (isUserBlockedAfterUpdatingInformation) 149 { 150 <div class="alert alert-warning mt-3"> 151 @Translate("Please wait one business day after updating your contact information for your account to be unblocked before attempting to claim any SPIFFs.") 152 </div> 153 } 154 155 <script type="module" src="Files/Templates/Designs/Swift/Assets/custom-js/custom-js-module/warrantyRegistration.js"></script> 156 157 <form method="post" onsubmit="WarrantyRegistration.ValidateSalesPersonInformationFormBeforeSubmit(event, this);" data-api-url="@Dna.Keystone.WebApi.Constants.WarrantyRoute" data-invalid-address-message="@Translate("Please enter a valid combination of City, State, and Zip.")" action="Default.aspx?ID=@Pageview.ID"> 158 <input type="hidden" name="@Dna.Keystone.Users.Constants.Request.IsSalesPersonInformationForm" value="1"> 159 160 <div class="grid p-3"> 161 162 <div class="g-col-12 g-col-lg-6"> 163 <div class="form-floating"> 164 <input type="text" class="form-control" placeholder="@Translate("First Name")" name="firstName" id="firstName" maxlength="25" value="@loginUser.FirstName" required="required"> 165 <label for="firstName" class="form-label">@Translate("First Name")</label> 166 </div> 167 </div> 168 169 <div class="g-col-12 g-col-lg-6"> 170 <div class="form-floating"> 171 <input type="text" class="form-control" placeholder="@Translate("Last Name")" name="lastName" id="lastName" maxlength="25" value="@loginUser.LastName" required="required"> 172 <label for="lastName" class="form-label">@Translate("Last Name")</label> 173 </div> 174 </div> 175 176 <div class="g-col-12"> 177 <div class="form-floating"> 178 <input type="text" class="form-control" placeholder="@Translate("Address 1")" name="address" id="address" value="@loginUser.Address" required="required"> 179 <label for="address" class="form-label">@Translate("Address 1")</label> 180 </div> 181 </div> 182 183 @if (regions.Count > 0) 184 { 185 countrySelectorColumnSize = "g-col-12 g-col-lg-3"; 186 } 187 188 <div class="@countrySelectorColumnSize"> 189 <div class="form-floating"> 190 <input type="text" class="form-control" placeholder="@Translate("Town / City")" name="city" id="city" value="@loginUser.City" required /> 191 <label for="city" class="form-label">@Translate("Town / City")</label> 192 </div> 193 </div> 194 195 @if (regions.Count > 0) 196 { 197 if (currentCountry == "CA") 198 { 199 regionLabel = Translate("Province"); 200 } 201 else if (currentCountry == "GB") 202 { 203 regionLabel = Translate("Region"); 204 } 205 else if (currentCountry == "US") 206 { 207 regionLabel = Translate("State"); 208 } 209 210 <div class="g-col-3"> 211 <div class="form-floating"> 212 @{ 213 string regionCode = loginUser.State; 214 215 <select class="form-select" name="state" id="state"> 216 @foreach (var region in regions) 217 { 218 string selected = region.RegionCode == regionCode ? "selected" : ""; 219 <option value="@region.RegionCode" @selected>@region.GetName(Dynamicweb.Ecommerce.Common.Context.LanguageID)</option> 220 } 221 </select> 222 } 223 <label for="state">@regionLabel</label> 224 </div> 225 </div> 226 } 227 else 228 { 229 <input type="hidden" name="state" id="state" value=""> 230 } 231 232 <div class="g-col-12 g-col-lg-3"> 233 <div class="form-floating"> 234 <input type="text" class="form-control" placeholder="@Translate("Zip")" name="zip" id="zip" value="@loginUser.Zip" required="required"> 235 <label for="zip" class="form-label">@Translate("Zip")</label> 236 </div> 237 </div> 238 239 <div class="g-col-12 g-col-lg-3"> 240 <div class="form-floating"> 241 @{ 242 <select class="form-select" id="countryCode" name="countryCode" onchange="submitForm()"> 243 @foreach (var country in Dynamicweb.Ecommerce.Services.Countries.GetCountries()) 244 { 245 string selected = country.Code2 == currentCountry ? "selected" : ""; 246 247 <option value="@country.Code2" @selected>@country.GetName(Pageview.Area.EcomLanguageId)</option> 248 } 249 </select> 250 } 251 <label for="countryCode" class="form-label">@Translate("Country")</label> 252 </div> 253 </div> 254 255 <div class="g-col-12 g-col-lg-3"> 256 <div class="form-floating"> 257 <input type="email" readonly class="form-control" placeholder="@Translate("Email")" name="email" id="email" value="@loginUser.Email" required /> 258 <label for="email" class="form-label">@Translate("Email")</label> 259 </div> 260 </div> 261 262 <div class="g-col-12 g-col-lg-3"> 263 <div class="form-floating"> 264 <input type="text" class="form-control" placeholder="@Translate("Phone")" name="phone" id="phone" value="@loginUser.Phone"> 265 <label for="phone" class="form-label">@Translate("Phone")</label> 266 </div> 267 </div> 268 269 <div class="g-col-12 g-col-lg-3"> 270 <div class="form-floating"> 271 <input type="text" class="form-control" placeholder="@Translate("Extension")" name="extension" id="extension" value="@(loginUserExtensionCustomField?.Value)"> 272 <label for="extension" class="form-label">@Translate("Extension")</label> 273 </div> 274 </div> 275 276 <div class="g-col-12 g-col-lg-3"> 277 <div class="form-floating"> 278 <input type="text" class="form-control" placeholder="@Translate("Fax")" name="fax" id="fax" value="@loginUser.Fax"> 279 <label for="fax" class="form-label">@Translate("Fax")</label> 280 </div> 281 </div> 282 283 @if (isLoginUserInBlockedSalesPersonRole) 284 { 285 <div class="g-col-12 g-col-lg-4"> 286 <div class="form-floating"> 287 <input type="text" class="form-control" placeholder="@Translate("SSN")" name="ssn" id="ssn" pattern="^(?:\d{3}-?\d{2}-?\d{4}|\d{3}-\d{3}-\d{3})$" title="@Translate("######### or ###-##-#### or ###-###-###")" value="@loginUserSsn" @formSsnFieldDisabledText required /> 288 <label for="ssn" class="form-label">@Translate("SSN")</label> 289 <div class="fs-7"> 290 @Translate("The SSN/Taxpayer Id format should be specified (US = XXX-XX-XXXX, CA = XXX-XXX-XXX)") 291 </div> 292 </div> 293 </div> 294 } 295 296 <div class="g-col-12"> 297 <button type="submit" class="btn btn-primary me-2" id="UpdateProfileButton">@Translate("Update")</button> 298 </div> 299 300 </div> 301 </form> 302 303 <script> 304 function submitForm() { 305 var form = document.querySelector("#UserManagementEditForm"); 306 form.requestSubmit(); 307 } 308 </script> 309 310 @if (!string.IsNullOrEmpty(apiKey)) 311 { 312 <script defer src="https://maps.googleapis.com/maps/api/js?key=@(apiKey)&libraries=places"></script> 313 314 <script type="module"> 315 var mapSettings = { currentCountry: "@currentCountry" }; 316 swift.Places.init(mapSettings); 317 </script> 318 }