Manage My Account | Martec International

Manage Accounts
Exception in template (Designs\Martec\TemplateRenderer/ManageAccounts.cshtml): System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.cefaeedafabfaf.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()
@inherits RazorTemplateBase<RazorTemplateModel<Template>> @using System @using System.Collections.Generic @using System.Linq @using Dynamicweb.Notifications @using Dynamicweb.Rendering; @using Dynamicweb.Security.UserManagement @functions{ const string pageParameter = "PageNum"; const int pageSize = 30; int currentPage = 1; int totalPages = 1; string searchedTerms = ""; } @{ searchedTerms = (System.Web.HttpContext.Current.Request["s"] ?? "").ToString().ToLower(); var showSetDefaultAccount = false; bool.TryParse((Pageview.Area.Item["ShowSetDefaultAccount"] ?? "").ToString(), out showSetDefaultAccount); var managePageAjax = 0; int.TryParse((Pageview.Area.Item["ManageAccountsAjax"] ?? "").ToString(), out managePageAjax); managePageAjax = managePageAjax > 0 ? managePageAjax : Pageview.Page.ID; var stopImpersonateAjaxUrl = string.Format("/Default.aspx?Id={0}&DwExtranetRemoveSecondaryUser=1", managePageAjax); var impersonateUsersBase = Pageview.User.CurrentSecondaryUser != null ? Pageview.User.CurrentSecondaryUser.GetUsersICanSetAsSecondary() : Pageview.User.GetUsersICanSetAsSecondary(); IEnumerable<Dynamicweb.Security.UserManagement.User> impersonateUsers = impersonateUsersBase; if (!string.IsNullOrEmpty(searchedTerms)) { impersonateUsers = impersonateUsersBase.Where(u => u.FirstName.ToLower().Contains(searchedTerms) || u.LastName.ToLower().Contains(searchedTerms) || u.Name.ToLower().Contains(searchedTerms) || u.CustomerNumber.ToLower().Contains(searchedTerms)); } var hasUsers = false; int.TryParse(System.Web.HttpContext.Current.Request[pageParameter], out currentPage); currentPage = currentPage > 1 ? currentPage : 1; var skipUsers = (currentPage - 1) * pageSize; totalPages = (int) Math.Ceiling((decimal) impersonateUsers.Count() / pageSize); } <div class="row"> <p class="col-xs-12 col-sm-6"> @Translate("manageAccountsIntro", "Click Manage Account to work with desired account.<br/>Return to manage account screen from the welcome menu.") </p> <form class="col-xs-12 col-sm-3 col-sm-offset-3 DMForms" action="/Default.aspx" id="searchUsersForm" class="form-inline"> <input type="hidden" name="ID" value='@Pageview.Page.ID'> <fieldset class="col-xs-10 TextInput noPadding"> <input placeholder='@Translate("searchCustomer", "Search customer")' type="text" name="s" value="@searchedTerms"/> </fieldset> <button type="submit" class="btn pull-right"> <i class="fa fa-search"></i> </button> </form> </div> <table id="switchAccount" class="col-xs-12 noPadding-xs noPadding-sm dataTable"> <tbody> @foreach (var user in impersonateUsers.OrderBy(u => u.Name).Skip(skipUsers).Take(pageSize)) { hasUsers = true; var userImpersonateUrl = string.Format("/Default.aspx?Id={0}&DWExtranetSecondaryUserSelector={1}&{2}={3}", Pageview.Page.ID, user.ID, pageParameter, currentPage); var isImpersonatedUser = user.ID == Pageview.User.ID; <tr> <td> <h3>@user.Name</h3> <p>@user.CustomerNumber</p> <p> @if (!string.IsNullOrEmpty(user.Address)) { <span>@user.Address,</span> <span>@user.City @user.State,</span> <span>@user.Zip</span> } </p> </td> <td class="text-right"> @if (isImpersonatedUser) { <a href="@(string.Format("/Default.aspx?Id={0}&DwExtranetRemoveSecondaryUser=1&{1}={2}", Pageview.Page.ID, pageParameter, currentPage))" class="btn btn-default">@Translate("stopManageAccount", "Stop")</a> } else { <a href="@userImpersonateUrl" action="@stopImpersonateAjaxUrl" class="selectAccount btn btn-bg">@Translate("manageAccount", "Manage Account")</a> } @if (showSetDefaultAccount) { if (Dna.AutoImpersonate.Helpers.ReadDefaultId(Pageview.User.CurrentSecondaryUser != null ? Pageview.User.CurrentSecondaryUser : Pageview.User) == user.ID.ToString()) { <a href="javascript:void(0);" class="btn btn-outline">@Translate("defaultAccount", "Default Account")</a> } else { <a href="@(string.Format("/Default.aspx?Id={0}&DefaultAccount={1}", managePageAjax, user.ID))" class="setDefaultAccount btn btn-bg">@Translate("setDefaultAccount", "Set Default Account")</a> } } </td> </tr> } @if (!hasUsers) { <tr> <td>No Accounts</td> </tr> } </tbody> </table> @RenderPagination() @SnippetStart("jsOnLoad") onLoadSwitchAccount(); @SnippetEnd("jsOnLoad") @helper RenderPagination() { var loopPageSize = 3; var newPageBaseUrl = string.Format("/Default.aspx?Id={0}", Pageview.Page.ID); if (!string.IsNullOrEmpty(searchedTerms)) { newPageBaseUrl += "&s=" + searchedTerms; } newPageBaseUrl += string.Format("&{0}=", pageParameter); if (totalPages > 1) { var active = ""; int thisPage = 0; var startPage = 1; var endPage = totalPages; var pageOffset = Math.Floor(Convert.ToDecimal(loopPageSize / 2)); var middlePage = pageOffset + 1; if (totalPages > loopPageSize) { startPage = (Convert.ToInt32(currentPage - pageOffset) < 1) ? 1 : Convert.ToInt32(currentPage - pageOffset); endPage = (Convert.ToInt32(currentPage + pageOffset) > totalPages) ? totalPages : Convert.ToInt32(currentPage + pageOffset); if (currentPage < middlePage) { endPage = loopPageSize; } else if (currentPage > middlePage) { if (totalPages < (currentPage + pageOffset)) { startPage = totalPages - loopPageSize; if (loopPageSize % 2 != 0) { startPage += 1; } } if (loopPageSize % 2 == 0) { startPage += 1; } } } <div class="footerBox col-xs-12"> <ul class="pagination"> @if (currentPage > 1) { @PageItem(0, (newPageBaseUrl + (currentPage - 1)), "&laquo; " + Translate("previous", "Previous") + " ") } @if (currentPage > 2 && totalPages > 3) { @PageItem(1, (newPageBaseUrl + 1), "1") @Ellipsis() } @for (var i = startPage; i <= endPage; i++) { @PageItem(i, (newPageBaseUrl + i), i.ToString()) } @if (currentPage < totalPages - 1 && totalPages > 3) { @Ellipsis() @PageItem(totalPages, (newPageBaseUrl + totalPages), totalPages.ToString()) } @if (currentPage < totalPages) { @PageItem(0, (newPageBaseUrl + (currentPage + 1)), " " + Translate("next", "Next") + " &raquo;") } </ul> </div> } } @helper PageItem(int pageNum, string href, string text) { var liClass = currentPage == pageNum ? "class=\"active\"" : ""; <li @liClass> <a href="@href">@text</a> </li> } @helper Ellipsis() { <li> <span>...</span> </li> }