dfmmalaw
4/3/2017 - 5:10 PM

Use ViewBag to determine if user is on a specific page

Use ViewBag to determine if user is on a specific page

@if (ControllerHelper.isCandidate() && (ViewBag.isChangingPassword == null))
{
    <li class="menuItem text" id="mainMenuProfile">
        <a href="@(ControllerHelper.isCandidate() ? Url.Action("Index", "Profile", new { area = "Candidates" }) : "#")">
            MY PROFILE
        </a>
    </li>

    if (ControllerHelper.showVolunteerCheckIn())
    {
        <li class="menuItem text @(ViewBag.Menu.sel("checkIn"))">
            <a href="@Url.Action("index", "VolunteerCheckIn", new { area = "Mains" })">
                APPROVAL LISTING
            </a>
        </li>
    }
}

@if (ViewBag.isChangingPassword == null) 
{
    <li class="menuItem text @(ViewBag.Menu.sel("contact"))">
        <a href="@Url.Action("contact", "Home", new { area = "Mains" })">
            CONTACT
        </a>
    </li>    
}

@if (ControllerHelper.isClient() && (ViewBag.isChangingPassword == null))
{
    <li class="menuItem text @(ViewBag.Menu.sel("org"))">
        <a href="@Url.Action("Index", "EConsent", new { area = "Clients" })">
            DASHBOARD
        </a>
    </li>

    if (ControllerHelper.showOrgCheckIn())
    {
        <li class="menuItem text @(ViewBag.Menu.sel("checkIn"))">
            <a href="@Url.Action("index", "VolunteerCheckIn", new { area = "Mains" })">
                APPROVAL LISTING
            </a>
        </li>
    }
}
else if (ControllerHelper.isCandidate() && (ViewBag.isChangingPassword == null))
{
    <li class="menuItem text @(ViewBag.Menu.sel("promo"))">
        @if (ControllerHelper.candidateHasProcessingOrder() || ControllerHelper.candidateHasCompletedOrder())
        {
            <a href="#" data-toggle="modal" class="blueText@(disableNonCandidate)" data-target="#orderStatus">GET VERIFIED</a>
        }
        else
        {
            <a href="@Url.Action("Index", "OrderPage", new {area = "Mains", askForGoodDeedCode = true, performOrderShareCheck = false})" class="blueText@(disableNonCandidate)">
                GET VERIFIED
            </a>
        }
    </li>
}
public ActionResult ChangePassword(ChangePasswordModel model)
{
    model.Action = "ChangePassword";
    if (!ModelState.IsValid)
        return View(model);
    // ChangePassword will throw an exception rather
    // than return false in certain failure scenarios.
    bool changePasswordSucceeded = false;
    try
    {
        MembershipUser currentUser = candidateProvider.GetUser(webRequestState.UserName, false);
        if (currentUser != null)
            changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
    }
    catch (Exception)
    {
        changePasswordSucceeded = false;
    }

    if (changePasswordSucceeded)
        return RedirectToAction("ChangePasswordSuccess");

    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
    model.PwdExpirationDays = appConfigService.VolPwdExpirationDays;
    // this property is created here and set to true, meaning they are going to be directed to "change password" page
    ViewBag.isChangingPassword = true;

    // If we got this far, something failed, redisplay form
    return View(model);
}

public ActionResult ChangePasswordClient(ChangePasswordModel model)
{            
    model.Action = "ChangePasswordClient";
    if (!ModelState.IsValid)
    {
        // this is created and set here and below at end of method
        ViewBag.isChangingPassword = true;
        return View("ChangePassword", model);                
    }
    bool changePasswordSucceeded = false;
    try
    {
        MembershipUser currentUser = clientProvider.GetUser(webRequestState.UserName, false);
        ClientUser clientUser = clientUserRepository.findByUserName(webRequestState.UserName);

        if (currentUser != null && clientUser != null)
        {
            changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);

            if (changePasswordSucceeded)
            {
                log.InfoFormat("Successfully change client user {0} password", webRequestState.UserName);
                clientUser.ChangePassword = false;
            }
            else
            {
                model.Message = String.Format("Could not verify current password");
                model.PwdExpirationDays = appConfigService.OrgPwdExpirationDays;
            }
        }
        else
        {
            Guid errorCode = log.warnGuidFormat("Could not find client user {0}", webRequestState.UserName);
            model.Message = String.Format("Could not find user information: {0} error code: {1}",
                webRequestState.UserName, errorCode);
        }
    }
    catch (Exception err)
    {
        Guid errorCode = log.warnGuidFormat(err, "Failed to change password with error: {0}",
            err.loggingMessage());
        model.Message = String.Format("Failed to change password with error: {0}", errorCode);
        changePasswordSucceeded = false;
    }

    if (changePasswordSucceeded)
        return RedirectToAction("ChangePasswordSuccessClient");

    ViewBag.isChangingPassword = true;
    return View("ChangePassword", model);
}