调整程序框架

This commit is contained in:
yubaolee
2015-05-23 12:10:53 +08:00
parent b4fc05a823
commit d2641d40fa
44 changed files with 434 additions and 635 deletions

View File

@@ -1,17 +1,16 @@
using System;
using System.Collections.Generic;
using OpenAuth.Domain.Utility;
namespace OpenAuth.Domain.Model
{
public partial class Button
public partial class Button : EntityBase<string>, IAggregateRoot
{
public Button()
{
this.RoleMenuButtons = new List<RoleMenuButton>();
this.Menus = new List<Menu>();
}
public string ButtonId { get; set; }
public string FullName { get; set; }
public string Img { get; set; }
public string Event { get; set; }
@@ -20,7 +19,10 @@ namespace OpenAuth.Domain.Model
public string Description { get; set; }
public bool Enabled { get; set; }
public Nullable<int> SortCode { get; set; }
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
public virtual ICollection<Menu> Menus { get; set; }
public virtual ICollection<Menu> Menus { get; set; }
protected override void Validate()
{
throw new NotImplementedException();
}
}
}

View File

@@ -1,11 +1,16 @@
using OpenAuth.Domain.Utility;
namespace OpenAuth.Domain.Model
{
public partial class DataPermission
public partial class DataPermission :EntityBase<string>, IAggregateRoot
{
public string Id { get; set; }
public string RoleId { get; set; }
public string ResourceId { get; set; }
public string ObjectId { get; set; }
public virtual Role Role { get; set; }
protected override void Validate()
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using OpenAuth.Domain.Utility;
namespace OpenAuth.Domain.Model
{
public partial class Department
public partial class Department : EntityBase<string>, IAggregateRoot
{
public Department()
{
@@ -11,7 +12,6 @@ namespace OpenAuth.Domain.Model
this.Users = new List<User>();
}
public string DepartmentId { get; set; }
public string ParentId { get; set; }
public string FullName { get; set; }
public string Description { get; set; }
@@ -20,5 +20,9 @@ namespace OpenAuth.Domain.Model
public bool DeleteMark { get; set; }
public virtual ICollection<Role> Roles { get; set; }
public virtual ICollection<User> Users { get; set; }
protected override void Validate()
{
throw new NotImplementedException();
}
}
}

View File

@@ -1,18 +1,22 @@
using System;
using System.Collections.Generic;
using OpenAuth.Domain.Utility;
namespace OpenAuth.Domain.Model
{
public partial class Menu
public partial class Menu :EntityBase<string>, IAggregateRoot
{
public Menu()
{
this.Buttons = new List<Button>();
this.Roles = new List<Role>();
this.RoleMenuButtons = new List<RoleMenuButton>();
}
public string MenuId { get; set; }
protected override void Validate()
{
throw new NotImplementedException();
}
public string ParentId { get; set; }
public string FullName { get; set; }
public string Description { get; set; }
@@ -26,6 +30,5 @@ namespace OpenAuth.Domain.Model
public Nullable<int> SortCode { get; set; }
public virtual ICollection<Button> Buttons { get; set; }
public virtual ICollection<Role> Roles { get; set; }
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
}
}

View File

@@ -1,19 +1,23 @@
using System;
using System.Collections.Generic;
using OpenAuth.Domain.Utility;
namespace OpenAuth.Domain.Model
{
public partial class Role
public partial class Role :EntityBase<string>, IAggregateRoot
{
public Role()
{
this.DataPermissions = new List<DataPermission>();
this.RoleMenus = new List<Menu>();
this.RoleMenuButtons = new List<RoleMenuButton>();
this.Users = new List<User>();
}
public string RoleId { get; set; }
protected override void Validate()
{
throw new NotImplementedException();
}
public string ParentId { get; set; }
public string FullName { get; set; }
public string Category { get; set; }
@@ -25,7 +29,6 @@ namespace OpenAuth.Domain.Model
public virtual ICollection<DataPermission> DataPermissions { get; set; }
public virtual Department Department { get; set; }
public virtual ICollection<Menu> RoleMenus { get; set; }
public virtual ICollection<RoleMenuButton> RoleMenuButtons { get; set; }
public virtual ICollection<User> Users { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
namespace OpenAuth.Domain.Model
{
public partial class RoleMenuButton
{
public string RoleMenuButtonId { get; set; }
public string RoleId { get; set; }
public string MenuId { get; set; }
public string ButtonId { get; set; }
public virtual Button Button { get; set; }
public virtual Menu Menu { get; set; }
public virtual Role Role { get; set; }
}
}

View File

@@ -4,7 +4,7 @@ using OpenAuth.Domain.Utility;
namespace OpenAuth.Domain.Model
{
public partial class User :EntityBase<string>
public partial class User :EntityBase<string>, IAggregateRoot
{
public User()
{

View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Linq;
namespace OpenAuth.Domain.Model
{
public partial class User
{
//加载用户的导航菜单项
public IEnumerable<Menu> LoadMenus()
{
var menus = new List<Menu>();
foreach (var role in Roles)
{
foreach (var menu in role.RoleMenus.Where(menu => !menus.Exists(e => e.Id == menu.Id)))
{
menus.Add(menu);
}
}
return menus;
}
}
}

View File

@@ -41,11 +41,11 @@
<ItemGroup>
<Compile Include="Interface\IMenuRepository.cs" />
<Compile Include="Interface\IUserRepository.cs" />
<Compile Include="ModelBehavior\User.cs" />
<Compile Include="Model\Button.cs" />
<Compile Include="Model\DataPermission.cs" />
<Compile Include="Model\Department.cs" />
<Compile Include="Model\Menu.cs" />
<Compile Include="Model\RoleMenuButton.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Model\Role.cs" />
<Compile Include="Model\User.cs" />
@@ -59,7 +59,6 @@
<Compile Include="Utility\ValueObjectBase.cs" />
<Compile Include="Utility\ValueObjectIsInvalidException.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -7,28 +7,6 @@ namespace OpenAuth.Domain.Service
{
public class MenuService
{
private IUserRepository _userRepository;
public MenuService(IUserRepository repository)
{
_userRepository = repository;
}
public List<Menu> GetMenuFor(string userId)
{
var menus = new List<Menu>();
var user = _userRepository.FindById(userId);
if (user != null)
{
foreach (var role in user.Roles)
{
foreach (var menu in role.RoleMenus.Where(menu => !menus.Exists(e =>e.MenuId == menu.MenuId)))
{
menus.Add(menu);
}
}
}
return menus;
}
}
}