mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-08 18:34:44 +08:00
修复部分BUG,完成为角色分配菜单的界面
This commit is contained in:
@@ -1,53 +1,110 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : Yubao Li
|
||||
// Created : 12-02-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 12-02-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleElementManagerApp.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>模块元素</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class ModuleElementManagerApp
|
||||
{
|
||||
private readonly IRepository<ModuleElement> _repository;
|
||||
|
||||
public ModuleElementManagerApp(IRepository<ModuleElement> repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public void AddOrUpdate(ModuleElement model)
|
||||
{
|
||||
if (model.Id == 0)
|
||||
{
|
||||
_repository.Add(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.Update(model);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ModuleElement> LoadByModuleId(int id)
|
||||
{
|
||||
var modules = _repository.Find(u => u.ModuleId == id);
|
||||
return modules;
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(u =>u.Id ==id);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : Yubao Li
|
||||
// Created : 12-02-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 12-02-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleElementManagerApp.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>模块元素</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.ViewModel;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class ModuleElementManagerApp
|
||||
{
|
||||
private readonly IRepository<ModuleElement> _repository;
|
||||
private IModuleRepository _moduleRepository;
|
||||
private IRelevanceRepository _relevanceRepository;
|
||||
|
||||
public ModuleElementManagerApp(IRepository<ModuleElement> repository,
|
||||
IRelevanceRepository relevanceRepository,
|
||||
IModuleRepository moduleRepository )
|
||||
{
|
||||
_repository = repository;
|
||||
_moduleRepository = moduleRepository;
|
||||
_relevanceRepository = relevanceRepository;
|
||||
}
|
||||
|
||||
public void AddOrUpdate(ModuleElement model)
|
||||
{
|
||||
if (model.Id == 0)
|
||||
{
|
||||
_repository.Add(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.Update(model);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ModuleElement> LoadByModuleId(int id)
|
||||
{
|
||||
var modules = _repository.Find(u => u.ModuleId == id);
|
||||
return modules;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取带有授权状态的菜单列表
|
||||
/// </summary>
|
||||
/// <param name="accessType">授权类型,当前有RoleElement/UserElement</param>
|
||||
/// <param name="firstId">
|
||||
/// 当为RoleElement时,表示RoleId
|
||||
/// 当为UserElement时,表示UserId
|
||||
/// </param>
|
||||
/// <param name="moduleId">模块ID</param>
|
||||
public List<ModuleElementVM> LoadWithAccess(string accessType, int firstId, int moduleId)
|
||||
{
|
||||
//TODO:多个Repository使用的是不同的Context不能进行联表查询,要用UnitOfWork处理
|
||||
//var results = from element in _repository.Find(u => u.ModuleId == moduleId)
|
||||
// join module in _moduleRepository.Find(null) on element.ModuleId equals module.Id
|
||||
// join relev in _relevanceRepository.Find(u => u.Key == accessType && u.FirstId == firstId)
|
||||
// on element.Id equals relev.SecondId into temp
|
||||
// from t in temp.DefaultIfEmpty()
|
||||
// select new ModuleElementVM
|
||||
// {
|
||||
// DomId = element.DomId,
|
||||
// Id = element.Id,
|
||||
// ModuleId = element.ModuleId,
|
||||
// ModuleName = module.Name,
|
||||
// Name = element.Name,
|
||||
// Accessed = t != null
|
||||
// };
|
||||
var listVms = new List<ModuleElementVM>();
|
||||
if (moduleId == 0) return listVms;
|
||||
string modulename = _moduleRepository.FindSingle(u => u.Id == moduleId).Name;
|
||||
|
||||
foreach (var element in LoadByModuleId(moduleId))
|
||||
{
|
||||
var accessed = _relevanceRepository.FindSingle(u =>u.Key == accessType
|
||||
&& u.FirstId == firstId && u.SecondId == element.Id);
|
||||
ModuleElementVM vm = new ModuleElementVM
|
||||
{
|
||||
Id = element.Id,
|
||||
Name = element.Name,
|
||||
ModuleId = element.ModuleId,
|
||||
DomId = element.DomId,
|
||||
ModuleName = modulename,
|
||||
Accessed = accessed != null
|
||||
};
|
||||
listVms.Add(vm);
|
||||
}
|
||||
return listVms;
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(u =>u.Id ==id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace OpenAuth.App
|
||||
_relevanceRepository.Find(u => u.FirstId == userId && u.Key == "UserModule")
|
||||
.Select(u => u.SecondId)
|
||||
.ToList();
|
||||
if (!moduleIds.Any()) return null;
|
||||
if (!moduleIds.Any()) return new List<Module>();
|
||||
return _repository.Find(u => moduleIds.Contains(u.Id)).ToList();
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace OpenAuth.App
|
||||
_relevanceRepository.Find(u => u.FirstId == roleId && u.Key == "RoleModule")
|
||||
.Select(u => u.SecondId)
|
||||
.ToList();
|
||||
if (!moduleIds.Any()) return null;
|
||||
if (!moduleIds.Any()) return new List<Module>();
|
||||
return _repository.Find(u => moduleIds.Contains(u.Id)).ToList();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="OrgManagerApp.cs" />
|
||||
<Compile Include="ViewModel\LoginUserVM.cs" />
|
||||
<Compile Include="ViewModel\ModuleElementVM.cs" />
|
||||
<Compile Include="ViewModel\ModuleView.cs" />
|
||||
<Compile Include="ViewModel\RoleVM.cs" />
|
||||
<Compile Include="ViewModel\UserView.cs" />
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace OpenAuth.App
|
||||
/// </summary>
|
||||
public dynamic Load(int orgId, int pageindex, int pagesize)
|
||||
{
|
||||
if (pageindex < 1) pageindex = 1; //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
|
||||
IEnumerable<Role> roles;
|
||||
int total = 0;
|
||||
if (orgId == 0)
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenAuth.App
|
||||
/// </summary>
|
||||
public dynamic Load(int orgId, int pageindex, int pagesize)
|
||||
{
|
||||
if (pageindex < 1) pageindex = 1; //如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
|
||||
if (pageindex < 1) pageindex = 1; //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
|
||||
IEnumerable<User> users;
|
||||
int total = 0;
|
||||
if (orgId == 0)
|
||||
|
||||
49
OpenAuth.App/ViewModel/ModuleElementVM.cs
Normal file
49
OpenAuth.App/ViewModel/ModuleElementVM.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public class ModuleElementVM
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DOM ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string DomId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
//模块ID
|
||||
public int ModuleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属模块名称
|
||||
/// </summary>
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权状态
|
||||
/// </summary>
|
||||
public bool Accessed { get; set; }
|
||||
|
||||
public ModuleElementVM()
|
||||
{
|
||||
this.Id = 0;
|
||||
this.DomId = string.Empty;
|
||||
this.Name = string.Empty;
|
||||
this.ModuleId = 0;
|
||||
this.ModuleName = string.Empty;
|
||||
this.Accessed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user