Manage Accounts

My Account

Manage Accounts

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