重构HeaderBarModel移除不用的ShowMenu,判断是否需要初始化前台菜单

This commit is contained in:
Argo-Lenovo 2016-12-20 13:30:38 +08:00
parent 0a7d3cd489
commit f51237f9ea
4 changed files with 11 additions and 12 deletions

View File

@ -19,8 +19,11 @@ namespace Bootstrap.Admin.Controllers
{ {
var v = new HeaderBarModel(); var v = new HeaderBarModel();
v.HomeUrl = DictHelper.RetrieveHomeUrl(); v.HomeUrl = DictHelper.RetrieveHomeUrl();
v.ShowMenu = true; if (v.HomeUrl.StartsWith("~/"))
if (v.HomeUrl.StartsWith("~/")) return View(v); {
v.Menus = MenuHelper.RetrieveLinksByUserName(User.Identity.Name);
return View(v);
}
else return Redirect(v.HomeUrl); else return Redirect(v.HomeUrl);
} }
/// <summary> /// <summary>

View File

@ -16,7 +16,7 @@ namespace Bootstrap.Admin.Models
DisplayName = user.DisplayName; DisplayName = user.DisplayName;
UserName = user.UserName; UserName = user.UserName;
UserID = user.ID; UserID = user.ID;
Menus = MenuHelper.RetrieveLinksByUserName(UserName); Menus = new List<Menu>();
} }
public string UserName { get; protected set; } public string UserName { get; protected set; }
/// <summary> /// <summary>
@ -30,15 +30,11 @@ namespace Bootstrap.Admin.Models
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public bool ShowMenu { get; set; }
/// <summary>
///
/// </summary>
public string HomeUrl { get; set; } public string HomeUrl { get; set; }
/// <summary> /// <summary>
/// 获得/设置 前台菜单 /// 获得/设置 前台菜单
/// </summary> /// </summary>
public IEnumerable<Menu> Menus { get; private set; } public IEnumerable<Menu> Menus { get; set; }
/// <summary> /// <summary>
/// 获得/设置 用户头像地址 /// 获得/设置 用户头像地址
/// </summary> /// </summary>

View File

@ -7,7 +7,7 @@
<span id="websiteTitle">@Model.Title</span> <span id="websiteTitle">@Model.Title</span>
</a> </a>
<!--logo end--> <!--logo end-->
@if (Model.Menus.Count() > 0 && Model.ShowMenu) @if (Model.Menus.Count() > 0)
{ {
<ul id="menu" class="dropdown-menu menu"> <ul id="menu" class="dropdown-menu menu">
<div class="arrow-up"></div> <div class="arrow-up"></div>
@ -21,7 +21,7 @@
</li> </li>
</ul> </ul>
} }
@if (!Model.ShowMenu && (LgbPrincipal.IsAdmin(User.Identity.Name) || User.IsInRole("Administrators"))) @if (LgbPrincipal.IsAdmin(User.Identity.Name) || User.IsInRole("Administrators"))
{ {
<!-- notification start --> <!-- notification start -->
<ul class="notify-row"> <ul class="notify-row">

View File

@ -83,9 +83,9 @@ namespace Bootstrap.DataAccess
return root; return root;
} }
/// <summary> /// <summary>
/// /// 通过当前用户名获得前台菜单
/// </summary> /// </summary>
/// <param name="userId"></param> /// <param name="userName">当前登陆的用户名</param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Menu> RetrieveLinksByUserName(string userName) public static IEnumerable<Menu> RetrieveLinksByUserName(string userName)
{ {