Manage Accounts

Error executing template "Designs/USKidsGolf/TemplateRenderer/ManageAccounts.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_5e2dabb53ff54f8a9814954767ac61fe.Execute() in c:\Domains\Sites\uskidsgolfpro.com\Files\Templates\Designs\USKidsGolf\TemplateRenderer\ManageAccounts.cshtml:line 22
   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.Collections.Generic 4 @using System.Linq 5 @using Dynamicweb.Rendering; 6 @using Dynamicweb.Security.UserManagement 7 @functions{ 8 const string pageParameter = "PageNum"; 9 const int pageSize = 30; 10 int currentPage = 1; 11 int totalPages = 1; 12 string searchedTerms = ""; 13 } 14 @{ 15 searchedTerms = (System.Web.HttpContext.Current.Request["s"] ?? "").ToString().ToLower(); 16 var showSetDefaultAccount = false; 17 bool.TryParse((Pageview.Area.Item[Dna.AutoImpersonate.Constants.AreaSettings.ShowDefaultAccount] ?? "").ToString(), out showSetDefaultAccount); 18 var managePageAjax = 0; 19 int.TryParse((Pageview.Area.Item[Dna.AutoImpersonate.Constants.AreaSettings.ManageAccountsAjax] ?? "").ToString(), out managePageAjax); 20 managePageAjax = managePageAjax > 0 ? managePageAjax : Pageview.Page.ID; 21 var stopImpersonateAjaxUrl = string.Format("/Default.aspx?Id={0}&DwExtranetRemoveSecondaryUser=1", managePageAjax); 22 var loginUser = Pageview.User.CurrentSecondaryUser != null ? Pageview.User.CurrentSecondaryUser : Pageview.User; 23 var impersonateUsers = UsKidsGolf.AutoImpersonationExtender.Helper.ReadUserForimpersonate(loginUser, Pageview) ?? new List<User>(); 24 var errors = System.Web.HttpContext.Current.Request[Dna.AutoImpersonate.Constants.Parameters.RequireManaging] != null ? Translate("selectAccountToManage", "Please select an account to manage before continuing") : string.Empty; 25 26 if (!string.IsNullOrEmpty(searchedTerms)) 27 { 28 impersonateUsers = impersonateUsers.Where(u => u.FirstName.ToLower().Contains(searchedTerms) || u.LastName.ToLower().Contains(searchedTerms) || u.Name.ToLower().Contains(searchedTerms) || u.CustomerNumber.ToLower().Contains(searchedTerms)); 29 } 30 31 var showStopBtn = loginUser.CustomFieldValues.FirstOrDefault(cf => cf.CustomField.SystemName.Equals(Dna.AutoImpersonate.Constants.CustomFields.ForceImpersonationSetting)).Value.Equals(Dna.AutoImpersonate.Constants.CustomFields.Options.UserNeverImpersonate); 32 var hasUsers = false; 33 var impersonateUsersCount = impersonateUsers.Count(); 34 int.TryParse(System.Web.HttpContext.Current.Request[pageParameter], out currentPage); 35 currentPage = currentPage > 1 ? currentPage : 1; 36 var skipUsers = (currentPage - 1) * pageSize; 37 totalPages = (int) Math.Ceiling((decimal) impersonateUsersCount / pageSize); 38 } 39 40 <div class="row"> 41 <p class="col-xs-12 col-sm-6"> 42 @Translate("manageAccountsIntro", "Click Manage Account to work with desired account.") 43 </p> 44 @if (impersonateUsersCount > 10 || !string.IsNullOrEmpty(searchedTerms)) 45 { 46 <form class="col-xs-12 col-sm-3 col-sm-offset-3 DMForms" action="/Default.aspx" id="searchUsersForm" class="form-inline"> 47 <input type="hidden" name="ID" value='@Pageview.Page.ID'> 48 <fieldset class="col-xs-12 TextInput noPadding"> 49 <input placeholder='@Translate("searchCustomer", "Search customer")' type="text" name="s" value="@searchedTerms"/> 50 </fieldset> 51 <button type="submit" class="btn pull-right"> 52 <i class="fa fa-search"></i> 53 </button> 54 </form> 55 } 56 </div> 57 58 <table id="switchAccount" class="col-xs-12 noPadding-xs noPadding-sm dataTable"> 59 <colgroup> 60 <col siz width="10%"/> 61 <col width="25%"/> 62 <col width="10%"/> 63 <col width="10%"/> 64 <col width="10%"/> 65 <col width="15%"/> 66 <col width="10%"/> 67 </colgroup> 68 <thead> 69 <tr> 70 <th>@Translate("customer#", "Customer No.")</th> 71 <th>@Translate("companyName", "Company Name")</th> 72 <th>@Translate("city", "City")</th> 73 <th>@Translate("zip", "Zip")</th> 74 <th>@Translate("state", "State")</th> 75 <th>@Translate("paymentTerms", "Payment Terms")</th> 76 <th>&nbsp;</th> 77 </tr> 78 </thead> 79 <tbody> 80 @foreach (var user in impersonateUsers.OrderBy(u => u.Name).Skip(skipUsers).Take(pageSize)) 81 { 82 hasUsers = true; 83 var userImpersonateUrl = string.Format("/Default.aspx?Id={0}&DWExtranetSecondaryUserSelector={1}&{2}={3}", Pageview.Page.ID, user.ID, pageParameter, currentPage); 84 var isImpersonatedUser = user.ID == Pageview.User.ID; 85 var paymentTermsField = user.CustomFieldValues.Find(cf => cf.CustomField.SystemName.Equals("AccessUser_PaymentTerms")); 86 var userStopImpersonateAjaxUrl = string.Format("{0}&DefaultAccount={1}", stopImpersonateAjaxUrl, user.ID); 87 88 <tr> 89 <td data-th="@(Translate("customer#", "Customer No."))">@user.CustomerNumber.Replace("ItalyCustomer-IT_","")</td> 90 <td data-th="@(Translate("companyName", "Company Name"))">@user.Name</td> 91 <td data-th="@(Translate("city", "City"))">@user.City</td> 92 <td data-th="@(Translate("zip", "Zip"))">@user.Zip</td> 93 <td data-th="@(Translate("state", "State"))">@user.State</td> 94 <td data-th="@(Translate("paymentTerms", "Payment Terms"))">@String.Format("{0}", paymentTermsField != null ? paymentTermsField.Value.ToString() : string.Empty)</td> 95 <td class="actions text-right"> 96 @if (isImpersonatedUser) 97 { 98 if (showStopBtn) 99 { 100 <a href="@(string.Format("/Default.aspx?Id={0}&DwExtranetRemoveSecondaryUser=1&{1}={2}", Pageview.Page.ID, pageParameter, currentPage))" class="btn btn-outline">@Translate("stopManageAccount", "Stop")</a> 101 } 102 else 103 { 104 <a disabled="disabled" class="btn btn-outline">@Translate("managingAccount", "Managing Account")</a> 105 } 106 } 107 else 108 { 109 <a href="@userImpersonateUrl" action="@userStopImpersonateAjaxUrl" class="selectAccount btn btn-bg">@Translate("manageAccount", "Manage Account")</a> 110 } 111 @if (showSetDefaultAccount) 112 { 113 if (Dna.AutoImpersonate.Helpers.ReadDefaultId(loginUser) == user.ID.ToString()) 114 { 115 <a href="javascript:void(0);" class="btn btn-outline">@Translate("defaultAccount", "Default Account")</a> 116 } 117 else 118 { 119 <a href="@(string.Format("/Default.aspx?Id={0}&DefaultAccount={1}", managePageAjax, user.ID))" class="setDefaultAccount btn btn-bg">@Translate("setDefaultAccount", "Set Default Account")</a> 120 } 121 } 122 </td> 123 </tr> 124 } 125 @if (!hasUsers) 126 { 127 <tr> 128 <td>No Accounts</td> 129 </tr> 130 } 131 </tbody> 132 </table> 133 @RenderPagination() 134 135 @SnippetStart("jsOnLoad") 136 onLoadSwitchAccount("@errors"); 137 @SnippetEnd("jsOnLoad") 138 139 @helper RenderPagination() 140 { 141 var loopPageSize = 3; 142 var newPageBaseUrl = string.Format("/Default.aspx?Id={0}", Pageview.Page.ID); 143 if (!string.IsNullOrEmpty(searchedTerms)) 144 { 145 newPageBaseUrl += "&s=" + searchedTerms; 146 } 147 newPageBaseUrl += string.Format("&{0}=", pageParameter); 148 149 if (totalPages > 1) 150 { 151 var active = ""; 152 int thisPage = 0; 153 154 var startPage = 1; 155 var endPage = totalPages; 156 var pageOffset = Math.Floor(Convert.ToDecimal(loopPageSize / 2)); 157 var middlePage = pageOffset + 1; 158 159 if (totalPages > loopPageSize) 160 { 161 startPage = (Convert.ToInt32(currentPage - pageOffset) < 1) ? 1 : Convert.ToInt32(currentPage - pageOffset); 162 endPage = (Convert.ToInt32(currentPage + pageOffset) > totalPages) ? totalPages : Convert.ToInt32(currentPage + pageOffset); 163 164 if (currentPage < middlePage) 165 { 166 endPage = loopPageSize; 167 } 168 else if (currentPage > middlePage) 169 { 170 if (totalPages < (currentPage + pageOffset)) 171 { 172 startPage = totalPages - loopPageSize; 173 if (loopPageSize % 2 != 0) 174 { 175 startPage += 1; 176 } 177 } 178 179 if (loopPageSize % 2 == 0) 180 { 181 startPage += 1; 182 } 183 } 184 } 185 <div class="footerBox col-xs-12"> 186 <ul class="pagination"> 187 @if (currentPage > 1) 188 { 189 @PageItem(0, (newPageBaseUrl + (currentPage - 1)), "&laquo; " + Translate("previous", "Previous") + " ") 190 } 191 @if (currentPage > 2 && totalPages > 3) 192 { 193 @PageItem(1, (newPageBaseUrl + 1), "1") 194 @Ellipsis() 195 } 196 @for (var i = startPage; i <= endPage; i++) 197 { 198 @PageItem(i, (newPageBaseUrl + i), i.ToString()) 199 } 200 @if (currentPage < totalPages - 1 && totalPages > 3) 201 { 202 @Ellipsis() 203 @PageItem(totalPages, (newPageBaseUrl + totalPages), totalPages.ToString()) 204 } 205 @if (currentPage < totalPages) 206 { 207 @PageItem(0, (newPageBaseUrl + (currentPage + 1)), " " + Translate("next", "Next") + " &raquo;") 208 } 209 </ul> 210 </div> 211 } 212 } 213 214 @helper PageItem(int pageNum, string href, string text) 215 { 216 var liClass = currentPage == pageNum ? "class=\"active\"" : ""; 217 <li @liClass> 218 <a href="@href">@text</a> 219 </li> 220 } 221 @helper Ellipsis() 222 { 223 <li> 224 <span>...</span> 225 </li> 226 }

Our Mission

The mission of U.S. Kids Golf is to help kids have fun learning the lifelong game of golf and encourage family interaction that builds lasting memories.