DDD领域模型数据访问权限之权限(十二)
实现权限的领域对象:BAS_Permission
public partial class BAS_Permission:AggreateRoot
{
private IRepository<BAS_Permission> irepository;
public BAS_Permission(IRepository<BAS_Permission> irepository)
{
this.irepository = irepository;
} /// <summary>
/// 创建权限
/// </summary>
/// <param name="name"></param>
/// <param name="codeproperty">[Name,UnitPrice]</param>
/// <param name="operationtype">0</param>
/// <param name="value">["Filed":"UntiPrice","Operator":"Equals","Value":"5000"]</param>
/// <param name="description"></param>
/// <param name="per_id"></param>
public void CreatePermission(string name,string codeproperty,OperationType operationtype,
string value,string description,Guid per_id)
{
var bas_permission = new BAS_Permission();
bas_permission.Id = base.Id;
bas_permission.Name = name;
bas_permission.Description = description;
bas_permission.CodeProperty = codeproperty;
bas_permission.CodeValue = value;
bas_permission.Per_Id = per_id;
irepository.Create(bas_permission);
}
/// <summary>
/// 根据权限名获取权限信息
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public BAS_Permission GetPermissionByName(string name)
{
return irepository.GetByCondition(p => p.Name == name, p => true)
.SingleOrDefault();
}
}
权限集合的领域对象:BAS_PermissionSet
public partial class BAS_PermissionSet:AggreateRoot
{
private IRepository<BAS_PermissionSet> irepository;
public BAS_PermissionSet(IRepository<BAS_PermissionSet> irepository)
{
this.irepository = irepository;
}
/// <summary>
/// 创建权限集对象
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <param name="per_id"></param>
public void CreatePermissionSet(string name,string description,Guid per_id)
{
var bas_permissionset = new BAS_PermissionSet();
bas_permissionset.Id = base.Id;
bas_permissionset.Name = name;
bas_permissionset.Description = description;
bas_permissionset.Per_Id = per_id;
irepository.Create(bas_permissionset);
}
/// <summary>
/// 根据权限集名获取权限集信息
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public BAS_PermissionSet GetPermissionSetByName(string name)
{
return irepository.GetByCondition(p => p.Name == name, p => true).SingleOrDefault();
}
}
权限和权限集合对应的关系:
public partial class BAS_PPSet:AggreateRoot
{
private IRepository<BAS_PPSet> irepository;
public BAS_PPSet(IRepository<BAS_PPSet> irepository)
{
this.irepository = irepository;
}
public BAS_PPSet() { } /// <summary>
/// 添加多个权限到权限集中
/// </summary>
/// <param name="permissions"></param>
/// <param name="permissionset"></param>
public void CreateBAS_PPS(List<BAS_Permission> permissions,BAS_PermissionSet
permissionset)
{
foreach(var permission in permissions)
{
var bas_ppset = new BAS_PPSet();
bas_ppset.Id = base.Id;
bas_ppset.BAS_Permission = permission;
bas_ppset.BAS_PermissionSet = permissionset;
irepository.Create(bas_ppset);
}
} /// <summary>
/// 根据权限查找PPSET
/// </summary>
/// <param name="permission"></param>
/// <returns></returns>
public List<BAS_PPSet> GetppsetByPermission(BAS_Permission permission)
{
return irepository.GetByCondition(p => p.BAS_Permission.Id == permission.Id,
p => true);
} /// <summary>
/// 根据权限集查找PPSET
/// </summary>
/// <param name="permission"></param>
/// <returns></returns>
public List<BAS_PPSet> GetppsetByPermissionSet(BAS_PermissionSet permissionset)
{
return irepository.GetByCondition(p => p.BAS_PermissionSet.Id == permissionset.Id,
p => true);
}
}
权限容器服务:
public partial class BAS_PermissionConatiner:AggreateRoot
{
private IRepository<BAS_PermissionConatiner> irepository;
public BAS_PermissionConatiner(IRepository<BAS_PermissionConatiner> irepository)
{
this.irepository = irepository;
}
public void CreatePermissionContainer(Guid per_id)
{
var bas_permissioncontainer = new BAS_PermissionConatiner();
bas_permissioncontainer.Id = per_id;
irepository.Create(bas_permissioncontainer);
}
}
权限服务:BAS_PermissionService
public class BAS_PermissionService
{
private IRepository<BAS_Permission> irepositorypermission;
private IRepository<BAS_PermissionConatiner> irepositorypermissioncontainer;
public BAS_PermissionService(IRepository<BAS_Permission> irepositorypermission,
IRepository<BAS_PermissionConatiner> irepositorypermissioncontainer)
{
this.irepositorypermission = irepositorypermission;
this.irepositorypermissioncontainer = irepositorypermissioncontainer;
}
/// <summary>
/// 创建权限
/// </summary>
/// <param name="name"></param>
/// <param name="codeproperty"></param>
/// <param name="operationtype"></param>
/// <param name="value"></param>
/// <param name="description"></param>
public void CreatePermission(string name,string codeproperty,OperationType
operationtype,string value,string description)
{
var bas_permission = new BAS_Permission(irepositorypermission);
var per_id = Guid.NewGuid();
bas_permission.CreatePermission(name, codeproperty, operationtype, value, description,
per_id); var bas_permissioncontainer = new BAS_PermissionConatiner(irepositorypermissioncontainer);
bas_permissioncontainer.CreatePermissionContainer(per_id);
}
}
权限和权限集合的服务:BAS_PPSetService
public class BAS_PPSetService
{
private IRepository<BAS_Permission> irepositorypermission;
private IRepository<BAS_PermissionSet> irepositorypermissionset;
private IRepository<BAS_PPSet> irepositoryppset;
BAS_PPSet bas_ppset; public BAS_PPSetService(IRepository<BAS_Permission> irepositorypermission,
IRepository<BAS_PermissionSet> irepositorypermissionset,
IRepository<BAS_PPSet> irepositoryppset)
{
this.irepositorypermission = irepositorypermission;
this.irepositorypermissionset = irepositorypermissionset;
this.irepositoryppset = irepositoryppset;
bas_ppset = new BAS_PPSet(irepositoryppset);
} /// <summary>
/// 创建多个权限到权限集中
/// </summary>
/// <param name="permissionnames"></param>
/// <param name="permissionsetname"></param> public void CreateBAS_PPS(string[] permissionnames,string permissionsetname)
{
var listpermission = new List<BAS_Permission>();
for(int i=0;i<permissionnames.Length;i++)
{
var permission =
irepositorypermission.GetByCondition(p => p.Name == permissionnames[i],
p => true).SingleOrDefault();
listpermission.Add(permission);
} var permissionset = irepositorypermissionset.GetByCondition(p => p.Name ==
permissionsetname, p => true).SingleOrDefault();
bas_ppset.CreateBAS_PPS(listpermission, permissionset);
} /// <summary>
/// 根据权限名获取PPSET
/// </summary>
/// <param name="permissionname"></param>
/// <returns></returns>
public List<BAS_PPSet> GEtppsetbyPermissionName(string permissionname)
{
var permission =
irepositorypermission.GetByCondition(p => p.Name == permissionname, p => true)
.SingleOrDefault();
return bas_ppset.GetppsetByPermission(permission);
}
/// <summary>
/// 根据权限集名获取PPSET
/// </summary>
/// <param name="permissionsetname"></param>
/// <returns></returns>
public List<BAS_PPSet> GEtppsetbyPermissionSetName(string permissionsetname)
{
var permissionset =
irepositorypermissionset.GetByCondition(p => p.Name == permissionsetname, p => true)
.SingleOrDefault();
return bas_ppset.GetppsetByPermissionSet(permissionset);
}
}
BAS_PermissionSetService:
public class BAS_PermissionSetService
{
private IRepository<BAS_PermissionSet> irepositorypermissionset;
private IRepository<BAS_Permission> irepositorypermission;
private IRepository<BAS_PPSet> irepositoryppset;
private IRepository<BAS_PermissionConatiner> irepositorypermissioncontainer;
BAS_PermissionSet bas_permissionset;
BAS_PPSet bas_ppset; public BAS_PermissionSetService(IRepository<BAS_PermissionSet> irepositorypermissionset,
IRepository<BAS_Permission> irepositorypermission,
IRepository<BAS_PPSet> irepositoryppset,
IRepository<BAS_PermissionConatiner> irepositorypermissioncontainer)
{
this.irepositorypermission = irepositorypermission;
this.irepositorypermissioncontainer = irepositorypermissioncontainer;
this.irepositorypermissionset = irepositorypermissionset;
this.irepositoryppset = irepositoryppset; bas_permissionset = new BAS_PermissionSet(irepositorypermissionset);
bas_ppset = new BAS_PPSet(irepositoryppset);
} /// <summary>
/// 创建权限集
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
public void CreatePermissionSet(string name,string description)
{
var per_id = Guid.NewGuid();
bas_permissionset.CreatePermissionSet(name, description, per_id); var permissioncontainer = new BAS_PermissionConatiner(irepositorypermissioncontainer);
permissioncontainer.CreatePermissionContainer(per_id);
} /// <summary>
/// 将多个权限添加到权限集中
/// </summary>
/// <param name="permissionnames"></param>
/// <param name="permissionsetname"></param>
public void AddPermissionToPermissionSet(List<string> permissionnames,
string permissionsetname)
{
var permissionset = bas_permissionset.GetPermissionSetByName(permissionsetname);
var permissions =new List<BAS_Permission>();
foreach(var permissionname in permissionnames)
{
var bas_permission =
new BAS_Permission(irepositorypermission);
var permission = bas_permission.GetPermissionByName(permissionname);
permissions.Add(permission);
} bas_ppset.CreateBAS_PPS(permissions, permissionset);
} /// <summary>
/// 根据权限名获取权限集的信息
/// </summary>
/// <param name="permissionname"></param>
/// <returns></returns>
public List<BAS_PermissionSet> GetPermissionSetByPermissionName(string permissionname)
{
var ppsets = new BAS_PPSetService(irepositorypermission, irepositorypermissionset, irepositoryppset)
.GEtppsetbyPermissionName(permissionname);
var listpermissionset = new List<BAS_PermissionSet>();
foreach(var ppset in ppsets)
{
var permissionset = irepositorypermissionset.GetByCondition
(p => p.Id == ppset.BAS_PermissionSet.Id, p => true).SingleOrDefault();
listpermissionset.Add(permissionset);
}
return listpermissionset;
} /// <summary>
/// 判断某个权限是否在某个权限集中
/// </summary>
/// <param name="permissionname"></param>
/// <param name="permissionsetname"></param>
/// <returns></returns>
public bool IsPermissionSetContainPermission(string permissionname,
string permissionsetname)
{
return GetPermissionSetByPermissionName(permissionname).
Contains(bas_permissionset.GetPermissionSetByName(permissionsetname));
}
}
在DDD.Application 应用服务:PermissionAppService
public class PermissionAppService
{
IRepositoryContext context = ServiecLocator.Instance.GetService(typeof(IRepositoryContext))
as IRepositoryContext;
IRepository<BAS_Permission> permissionrepository = ServiecLocator.Instance.GetService(typeof(IRepository<BAS_Permission>))
as IRepository<BAS_Permission>;
IRepository<BAS_PermissionConatiner> permissioncontainerrepository = ServiecLocator.Instance.GetService(typeof(IRepository<BAS_PermissionConatiner>))
as IRepository<BAS_PermissionConatiner>; BAS_PermissionService bas_permissionservice;
BAS_Permission bas_permission; public PermissionAppService()
{
bas_permissionservice = new BAS_PermissionService
(permissionrepository, permissioncontainerrepository);
bas_permission = new BAS_Permission(permissionrepository);
} /// <summary>
/// 权限的创建
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <param name="codeproperty"></param>
/// <param name="codevalue"></param>
/// <param name="operationtype"></param>
public void CreatePermission(string name,string description,string codeproperty,
string codevalue,OperationType operationtype)
{
bas_permissionservice.CreatePermission(name, codeproperty, operationtype, codevalue, description);
context.Commit();
} /// <summary>
/// 根据权限名获取权限信息
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public BAS_Permission GetPermissionByName(string name)
{
return bas_permission.GetPermissionByName(name);
} public void CreatePermission(string v1, string v2, string v3, string v4, object operationType)
{
throw new NotImplementedException();
}
}
PermissionSetAppService
public class PermissionSetAppService
{
IRepositoryContext context = ServiecLocator.Instance.GetService(typeof(IRepositoryContext))
as IRepositoryContext;
IRepository<BAS_Permission> permissionrepository = ServiecLocator.Instance.GetService(typeof(IRepository<BAS_Permission>))
as IRepository<BAS_Permission>;
IRepository<BAS_PermissionConatiner> permissioncontainerrepository = ServiecLocator.Instance.GetService(typeof(IRepository<BAS_PermissionConatiner>))
as IRepository<BAS_PermissionConatiner>;
IRepository<BAS_PermissionSet> permissionsetrepository = ServiecLocator.Instance.GetService(typeof(IRepository<BAS_PermissionSet>))
as IRepository<BAS_PermissionSet>;
IRepository<BAS_PPSet> ppsetrepository = ServiecLocator.Instance.GetService(typeof(IRepository<BAS_PPSet>))
as IRepository<BAS_PPSet>; BAS_PermissionSetService bas_permissionsetservice;
BAS_PermissionSet bas_permissionset; public PermissionSetAppService()
{
bas_permissionsetservice = new BAS_PermissionSetService(permissionsetrepository,
permissionrepository, ppsetrepository, permissioncontainerrepository);
bas_permissionset = new BAS_PermissionSet(permissionsetrepository);
}
/// <summary>
/// 创建权限集
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
public void CreatePermissionSet(string name,string description)
{
bas_permissionsetservice.CreatePermissionSet(name, description);
context.Commit();
}
/// <summary>
/// 根据权限集名获取权限集信息
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public BAS_PermissionSet GetPermissionSetByName(string name)
{
return bas_permissionset.GetPermissionSetByName(name);
} /// <summary>
/// 添加多个权限到权限集
/// </summary>
/// <param name="permissionnames"></param>
/// <param name="permissionsetname"></param>
public void AddPermissionToPermissionSet(string[] permissionnames,string
permissionsetname)
{
bas_permissionsetservice.AddPermissionToPermissionSet(permissionnames
.ToList(), permissionsetname);
context.Commit();
} /// <summary>
/// 判断某个权限是否在某个权限集中
/// </summary>
/// <param name="permissionname"></param>
/// <param name="permissionsetname"></param>
/// <returns></returns>
public bool IsPermissionSetContainpermission(string permissionname,
string permissionsetname)
{
return bas_permissionsetservice.IsPermissionSetContainPermission(permissionname,
permissionsetname);
}
}
测试代码:
[TestMethod]
public void AddPermission()
{
PermissionAppService permissionservice =
new PermissionAppService();
permissionservice.CreatePermission("产品信息权限", "代表一个产品权限信息", "[ProductName,UnitPrice]",
"[{\"Field\":\"UnitPrice\",\"Operator\":\"Equal\",\"Value\":\"10\",\"Relation\":\"And\"}]",
Domain.OperationType.Read);
Assert.IsNotNull(permissionservice.GetPermissionByName("产品信息权限"));
} [TestMethod]
public void AddPermissionSet()
{
PermissionSetAppService permissionsetservice =
new PermissionSetAppService();
permissionsetservice.CreatePermissionSet("普通用户权限集", "代表普通用户的一个权限集");
Assert.IsNotNull(permissionsetservice.GetPermissionSetByName("普通用户权限集"));
} [TestMethod]
public void AddPermissionToPermissionSet()
{
PermissionSetAppService permissionsetservice =
new PermissionSetAppService();
string[] permissionnames = new string[1];
permissionnames[0] = "产品信息权限";
permissionsetservice.AddPermissionToPermissionSet(permissionnames,
"普通用户权限集");
Assert.IsTrue(permissionsetservice.IsPermissionSetContainpermission("产品信息权限", "普通用户权限集"));
}
DDD领域模型数据访问权限之权限(十二)的更多相关文章
- DDD领域模型数据访问权限之用户权限(十)
BAS_PRService岗位和角色服务: public class BAS_PRService { //岗位 private IRepository<BAS_Post> ireposit ...
- DDD领域模型数据访问权限(九)
权限分为:数据权限和功能权限 数据权限: 查询提供附加表达式的支持: //提供附加表达式的支持 List<TAggreateRoot> GetByCondition(Expression& ...
- DDD领域模型数据访问之对象(十一)
在工程DDD.Domain中文件夹ModelPermission新建类:BAS_Object public partial class BAS_Obejct:AggreateRoot { //仓储接口 ...
- 如何一步一步用DDD设计一个电商网站(十二)—— 提交并生成订单
阅读目录 前言 解决数据一致性的方案 回到DDD 设计 实现 结语 一.前言 之前的十一篇把用户购买商品并提交订单整个流程上的中间环节都过了一遍.现在来到了这最后一个环节,提交订单.单从业务上看,这个 ...
- Spring Security教程之基于方法的权限控制(十二)
目录 1.1 intercept-methods定义方法权限控制 1.2 使用pointcut定义方法权限控制 1.3 使用注解定义方法权限控制 1.3.1 JSR-25 ...
- C#与数据库访问技术总结(十二)数据阅读器(DataReader)2
遍历数据阅读器中的记录 当ExecuteReader方法返回DataReader对象时,当前光标的位置在第一条记录的前面. 必须调用阅读器的Read方法把光标移动到第一条记录,然后,第一条记录将变成当 ...
- 【大数据应用技术】作业十二|Hadoop综合大作业
本次作业的要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3339 前言 本次作业是在<爬虫大作业>的基础上进行的 ...
- 数据可视化基础专题(十二):Matplotlib 基础(四)常用图表(二)气泡图、堆叠图、雷达图、饼图、
1 气泡图 气泡图和上面的散点图非常类似,只是点的大小不一样,而且是通过参数 s 来进行控制的,多的不说,还是看个示例: 例子一: import matplotlib.pyplot as plt im ...
- 大数据之路【第十二篇】:数据挖掘--NLP文本相似度
一.词频----TF • 假设:如果一个词很重要,应该会在文章中多次出现 • 词频——TF(Term Frequency):一个词在文章中出现的次数 • 也不是绝对的!出现次数最多的是“的”“是”“在 ...
随机推荐
- UVALive - 3266 Tian Ji -- The Horse Racing(贪心)
题目链接 题意 两人赛马,每居获胜得200,平局无事发生,输了也输200.求最优的策略使赢的钱最多. 分析 排序,从最快的开始比,若比不过,则用最弱的消耗最强的.模拟即可. #include<i ...
- vue项目首次加载过慢
vue项目优化 浅谈 Vue 项目优化 关于vue在app首次加载缓慢的解决办法 nginx开启缓存 在http部分加入 #要想开启nginx的缓存功能,需要添加此处的两行内容! #设置Web缓存区名 ...
- storm-starter 例子学习
storm-starter 是 apache storm 针对初学者的一个用maven管理的项目示例.这篇文章记录storm-starter例子代码分析及执行. 参考:https://github.c ...
- fastreport报表中出现十字线
问题描述:经常有十字线出现在报表中,出现在报表中不同的频带,在预览和运行时都会显示,不能点击和删除它. 解决方法:这是一个线控制,因太小而不能被渲染,所以fastreport使用十字线来表示其位置.通 ...
- 基于报错的SQL注入整理
SQLServer 一.利用错误消息提取信息 输入 'having 1=1 --(having一般要与group by一起来使用,group by是用来进行分组的,having后面是用来进行判断的), ...
- mongoDB - 日常操作三
MongoDB 进程控制 进程控制 db.currentOp() # 查看活动进程 db.$cmd.sys.inprog.findOne() # 查看活动进程 与上面一样 opid # 操作进程号 o ...
- luogu P2900 [USACO08MAR]土地征用Land Acquisition
写这道题时,预处理部分少打了等号,吓得我以为斜率优化错了或者被卡精了 mmp 首先有一个很明显的结论(逃),就是一个土地如果长(\(x\))与宽(\(y\))都比另一个土地小,那么这个土地一定可以跟那 ...
- 修改mysql的用户root密码
第一种方法:root用户登录系统/usr/local/mysql/bin/mysqladmin -u root -p password 新密码enter password 旧密码 第二种方法:root ...
- MongoDB的增删查改基本操作
MongoDB的增删查改基本操作 先决条件建库.建集合.建文档 连接mongo,如果连接不上什么连接拒绝,输入mongod命令,启动服务后 输入mongo show dbs 显示当前的所有的数据库 一 ...
- GCC的符号可见性——解决多个库同名符号冲突问题
引用自:https://github.com/wwbmmm/blog/wiki/gcc_visibility 问题 最近项目遇到一些问题,场景如下 主程序依赖了两个库libA的funcA函数和libB ...