实现权限的领域对象: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领域模型数据访问权限之权限(十二)的更多相关文章

  1. DDD领域模型数据访问权限之用户权限(十)

    BAS_PRService岗位和角色服务: public class BAS_PRService { //岗位 private IRepository<BAS_Post> ireposit ...

  2. DDD领域模型数据访问权限(九)

    权限分为:数据权限和功能权限 数据权限: 查询提供附加表达式的支持: //提供附加表达式的支持 List<TAggreateRoot> GetByCondition(Expression& ...

  3. DDD领域模型数据访问之对象(十一)

    在工程DDD.Domain中文件夹ModelPermission新建类:BAS_Object public partial class BAS_Obejct:AggreateRoot { //仓储接口 ...

  4. 如何一步一步用DDD设计一个电商网站(十二)—— 提交并生成订单

    阅读目录 前言 解决数据一致性的方案 回到DDD 设计 实现 结语 一.前言 之前的十一篇把用户购买商品并提交订单整个流程上的中间环节都过了一遍.现在来到了这最后一个环节,提交订单.单从业务上看,这个 ...

  5. Spring Security教程之基于方法的权限控制(十二)

    目录 1.1     intercept-methods定义方法权限控制 1.2     使用pointcut定义方法权限控制 1.3     使用注解定义方法权限控制 1.3.1    JSR-25 ...

  6. C#与数据库访问技术总结(十二)数据阅读器(DataReader)2

    遍历数据阅读器中的记录 当ExecuteReader方法返回DataReader对象时,当前光标的位置在第一条记录的前面. 必须调用阅读器的Read方法把光标移动到第一条记录,然后,第一条记录将变成当 ...

  7. 【大数据应用技术】作业十二|Hadoop综合大作业

    本次作业的要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3339 前言 本次作业是在<爬虫大作业>的基础上进行的 ...

  8. 数据可视化基础专题(十二):Matplotlib 基础(四)常用图表(二)气泡图、堆叠图、雷达图、饼图、

    1 气泡图 气泡图和上面的散点图非常类似,只是点的大小不一样,而且是通过参数 s 来进行控制的,多的不说,还是看个示例: 例子一: import matplotlib.pyplot as plt im ...

  9. 大数据之路【第十二篇】:数据挖掘--NLP文本相似度

    一.词频----TF • 假设:如果一个词很重要,应该会在文章中多次出现 • 词频——TF(Term Frequency):一个词在文章中出现的次数 • 也不是绝对的!出现次数最多的是“的”“是”“在 ...

随机推荐

  1. vue基础篇---路由的实现

    路由可以有两种实现方式,一种是标签形式的,一种是js实现. 标签: <router-link to='/city'> 北京 </router-link> 标签还有另外一种实现方 ...

  2. PHP7 学习笔记(六)403 Forbidden - WAMP Server 2.5

    今天在wamp目录下有一个项目:comment 我在我的Windows 7机器上安装了WAMP版本2.5. 当浏览器浏览到本地主机时,WAMP服务器页面是可见的. 但是当我浏览到我的本地主机在我的移动 ...

  3. Linux 命令详解(三)./configure、make、make install 命令

    这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤 一.基本信息 1../configure 是用来检测你的安装平台的目标特征的.比如它会检测你是不是有CC或GCC,并不 ...

  4. [C++]指针/指针数组/数组指针/多维指针/单值指针/多值指针

    int main(){ //单值指针(指向单个值得指针,类同普通变量) int *px = new int; *px = 100; printf("%d",*px); delete ...

  5. Sqoop入门

    1 下载地址         http://archive.cloudera.com/cdh5/cdh/5/         版本 sqoop-1.4.6-cdh5.7.0         安装包   ...

  6. 如何手动删除服务?Windows手动删除服务列表中残留服务的方法

    https://www.jb51.net/os/windows/267738.html

  7. CentOS7_JDK安装和环境变量配置

    1.下载 curl -O http://download.Oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz 2.改名 mv ...

  8. SpringBoot整合Jest操作ES

    (1).添加依赖 <dependency> <groupId>io.searchbox</groupId> <artifactId>jest</a ...

  9. WEBSHELL恶意代码批量提取清除工具

    场景 使用D盾扫描到WEBSHELL后可以导出有路径的文本文件. 最后手动去把WEBSHELL复制到桌面然后以文件路径命名,挨个删除. D盾界面是这样的. 手动一个个找WEBSHELL并且改名效率太低 ...

  10. 【黑客免杀攻防】读书笔记8 - 软件逆向工程基础2(if-else,三目运算符)

    0x1 if-else分支 if-else分支4种状态 1.1 以常量为判断条件的简单if-else分支 C源代码: 单层if-else判断,常量为判断条件 int _tmain(int argc, ...