mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 01:58:01 +08:00
完成用户模块/用户角色分配
This commit is contained in:
@@ -114,6 +114,12 @@ namespace OpenAuth.App
|
||||
}
|
||||
}
|
||||
|
||||
public void AccessModules(int userId, int[] ids)
|
||||
{
|
||||
_userModuleRepository.DeleteByUser(userId);
|
||||
_userModuleRepository.AddUserModule(userId, ids);
|
||||
}
|
||||
|
||||
#region 私有方法
|
||||
|
||||
//根据同一级中最大的语义ID
|
||||
|
@@ -50,6 +50,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="OrgManagerApp.cs" />
|
||||
<Compile Include="ViewModel\ModuleView.cs" />
|
||||
<Compile Include="ViewModel\RoleVM.cs" />
|
||||
<Compile Include="ViewModel\UserView.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@@ -4,6 +4,7 @@ using OpenAuth.Domain.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Security;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
@@ -11,12 +12,15 @@ namespace OpenAuth.App
|
||||
{
|
||||
private IRoleRepository _repository;
|
||||
private IOrgRepository _orgRepository;
|
||||
private IUserRoleRepository _userRoleRepository;
|
||||
|
||||
public RoleManagerApp(IRoleRepository repository,
|
||||
IOrgRepository orgRepository)
|
||||
IOrgRepository orgRepository,
|
||||
IUserRoleRepository userRoleRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_orgRepository = orgRepository;
|
||||
_userRoleRepository = userRoleRepository;
|
||||
}
|
||||
|
||||
public int GetRoleCntInOrg(int orgId)
|
||||
@@ -45,12 +49,12 @@ namespace OpenAuth.App
|
||||
}
|
||||
else
|
||||
{
|
||||
roles = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
|
||||
roles = _repository.LoadInOrgs(pageindex, pagesize, GetSubOrgIds(orgId));
|
||||
total = _repository.GetRoleCntInOrgs(orgId);
|
||||
}
|
||||
|
||||
|
||||
return new
|
||||
|
||||
return new
|
||||
{
|
||||
total = total,
|
||||
list = roles,
|
||||
@@ -70,8 +74,8 @@ namespace OpenAuth.App
|
||||
|
||||
public Role Find(int id)
|
||||
{
|
||||
var role = _repository.FindSingle(u => u.Id == id);
|
||||
if(role == null) role = new Role();
|
||||
var role = _repository.FindSingle(u => u.Id == id);
|
||||
if (role == null) role = new Role();
|
||||
return role;
|
||||
|
||||
}
|
||||
@@ -95,6 +99,25 @@ namespace OpenAuth.App
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<RoleVM> LoadWithUser(int userId)
|
||||
{
|
||||
var roleIds = _repository.Find(null).ToList();
|
||||
var rolevms = new List<RoleVM>();
|
||||
foreach (var role in roleIds)
|
||||
{
|
||||
RoleVM rolevm = role;
|
||||
rolevm.IsBelongUser = (_userRoleRepository.FindSingle(u => u.RoleId == role.Id && u.UserId == userId) !=
|
||||
null);
|
||||
rolevms.Add(rolevm);
|
||||
}
|
||||
return rolevms;
|
||||
}
|
||||
|
||||
public void AccessRole(int userId, int[] roleIds)
|
||||
{
|
||||
_userRoleRepository.DeleteByUser(userId);
|
||||
_userRoleRepository.AddUserRole(userId, roleIds);
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,15 +11,12 @@ namespace OpenAuth.App
|
||||
{
|
||||
private IUserRepository _repository;
|
||||
private IOrgRepository _orgRepository;
|
||||
private IUserModuleRepository _usermoduleRepository;
|
||||
|
||||
public UserManagerApp(IUserRepository repository,
|
||||
IOrgRepository orgRepository,
|
||||
IUserModuleRepository usermoduleRepository)
|
||||
IOrgRepository orgRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_orgRepository = orgRepository;
|
||||
_usermoduleRepository = usermoduleRepository;
|
||||
}
|
||||
|
||||
public int GetUserCntInOrg(int orgId)
|
||||
@@ -115,11 +112,5 @@ namespace OpenAuth.App
|
||||
_repository.SetOrg(user.Id, orgIds);
|
||||
}
|
||||
|
||||
|
||||
public void AccessModules(int userId, int[] ids)
|
||||
{
|
||||
_usermoduleRepository.DeleteByUser(userId);
|
||||
_usermoduleRepository.AddUserModule(userId, ids);
|
||||
}
|
||||
}
|
||||
}
|
64
OpenAuth.App/ViewModel/RoleVM.cs
Normal file
64
OpenAuth.App/ViewModel/RoleVM.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : yubaolee
|
||||
// Created : 11-29-2015
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 11-29-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleVM.cs" company="www.cnblogs.com/yubaolee">
|
||||
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>角色模型视图</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
public partial class RoleVM
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 所属部门节点语义ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string OrgCascadeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属部门名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string OrgName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///是否属于某用户
|
||||
/// </summary>
|
||||
public bool IsBelongUser { get; set; }
|
||||
|
||||
public static implicit operator RoleVM(Role role)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<Role,RoleVM>(role);
|
||||
}
|
||||
|
||||
public static implicit operator Role(RoleVM rolevm)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<RoleVM, Role>(rolevm);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user