﻿@functions {
    private string GetCssClass(string actionName, string controllerName)
    {
        var currentControllerName = ViewContext.RouteData.Values["controller"].ToString();

        var isCurrentController = currentControllerName == controllerName;
        if (currentControllerName == "Home")
        {
            return GetHomeControllerLinksCssClass(actionName, isCurrentController);
        }
        
        return isCurrentController ? "active" : string.Empty;
    }

    private string GetHomeControllerLinksCssClass(string actionName, bool isCurrentController)
    {
        if (!isCurrentController)
        {
            return string.Empty;
        }
        
        var isCurrentAction = ViewContext.RouteData.Values["action"].ToString() == actionName;

        return isCurrentAction ? "active" : string.Empty;
    }

}

@helper GetMenuBarLink(string linkText, string actionName, string controllerName)
{
    <li class="@GetCssClass(actionName, controllerName)">@Html.ActionLink(linkText, actionName, controllerName)</li>
}

<ul class="nav">
    @GetMenuBarLink("Home", "Index", "Home")
    @GetMenuBarLink("Concerts", "Index", "Concerts")
    @GetMenuBarLink("Rehearsals", "Index", "Rehearsals")
    @GetMenuBarLink("About", "About", "Home")
    @GetMenuBarLink("Contact", "Contact", "Home")
</ul>

﻿@functions {
    private string GetCssClass(string actionName, string controllerName)
    {
        var currentControllerName = ViewContext.RouteData.Values["controller"].ToString();

        var isCurrentController = currentControllerName == controllerName;
        if (currentControllerName == "Home")
        {
            return GetHomeControllerLinksCssClass(actionName, isCurrentController);
        }
        
        return isCurrentController ? "active" : string.Empty;
    }

    private string GetHomeControllerLinksCssClass(string actionName, bool isCurrentController)
    {
        if (!isCurrentController)
        {
            return string.Empty;
        }
        
        var isCurrentAction = ViewContext.RouteData.Values["action"].ToString() == actionName;

        return isCurrentAction ? "active" : string.Empty;
    }

}

@helper GetMenuBarLink(string linkText, string actionName, string controllerName)
{
    <li class="dropdown @GetCssClass(actionName, controllerName)">
        @if (controllerName == "Concerts" && Request.IsAuthenticated)
        {
            <a href="@Url.Action(actionName, controllerName)" class="dropdown-toggle" data-toggle="dropdown">
                @linkText
                <b class="caret"></b>
            </a>
            
            <ul class="dropdown-menu">
                <li>@Html.ActionLink("Administer Concerts", "List", "Concerts")</li>
            </ul>
        }
        else
        {
            @Html.ActionLink(linkText, actionName, controllerName)
        }
    </li>
}

<ul class="nav">
    @GetMenuBarLink("Home", "Index", "Home")
    @GetMenuBarLink("Concerts", "Index", "Concerts")
    @GetMenuBarLink("Rehearsals", "Index", "Rehearsals")
    @GetMenuBarLink("About", "About", "Home")
    @GetMenuBarLink("Contact", "Contact", "Home")
</ul>

Add drop-down menu for concerts.
Add drop-down menu for concerts.

Hacky approach for now, just to get the link displayed.  A controller will be needed to wrap up this logic when the next feature is developed.
