上篇文章主要讲述了经销商上下文的需求与POCO对象,这篇文章主要讲述该界限上下文的仓储与领域逻辑的实现。

关于界限上下文与EF Core数据访问上下文参考产品上下文相应的实现,这里不再累述。

因为在经销商上下文中有两个聚合,一个是经销商聚合,一个是登录聚合,所以我们需要实现两个仓储接口:

1.经销商仓储接口定义:

 public interface IDealerRepository
{
void CreateDealer<T>(T dealer) where T : class, IAggregationRoot;
//获取上级经销商(当前代注册经销商)的层次结构
int GetParentDealerLayer(Guid dealerid);
//将上级经销商(代注册经销商)的子个数加一
void AddParentSubCount(Guid? parentdealerid);
//减去父进销商的电子币(用于注册和下单时,扣减经销商的电子币)
void SubParentEleMoney(Guid parentdealerid, decimal subelemoney);
//下订单时,增加经销商的PV
void AddDealerPV(Guid dealerid, decimal orderpv); }

2.登录仓储接口定义:

 public interface ILoginRepository
{
void CreateLogin<T>(T login) where T : class, IAggregationRoot;
Guid UserLogin(string tel, string password);
}

3.具体对应的仓储实现在仓储实现的项目中自己实现,主要通过EF Core完成数据库的访问与操作。

4.经销商聚合中联系人对象的领域逻辑实现:

public partial class Contact
{
public Contact CreateContact(Guid dealerid,string name,string tel,string province,string city,
string zero,string street,int isdefault)
{
this.Id = Guid.NewGuid();
this.DealerId = dealerid;
this.ContactName = name;
this.ContactTel = tel;
this.Province = province;
this.City = city;
this.Zero = zero;
this.Street = street;
switch (isdefault)
{
case :this.IsDefault = IsDefaultContact.默认;
break;
case :this.IsDefault = IsDefaultContact.非默认;
break;
}
return this; }
}

5.经销商聚合中经销商层次结构对象的领域逻辑实现:

 public partial class DealerTree
{
private readonly IDealerRepository idealerrepository;
public DealerTree(IDealerRepository idealerrepository)
{
this.idealerrepository = idealerrepository;
}
public DealerTree CreateDealerTree(Guid? parentdealerid,Guid dealerid)
{
this.Id = Guid.NewGuid();
this.DealerId = dealerid;
this.ParentDealerId = parentdealerid;
this.Layer = parentdealerid == null ? : idealerrepository.GetParentDealerLayer(Guid.Parse(parentdealerid.ToString())) + ;
return this;
}
}

6.经销商聚合中经销商对象的领域逻辑实现:

 public partial class Dealers
{
private readonly IDealerRepository idealerrepository;
public Dealers(IDealerRepository idealerrepository)
{
this.idealerrepository = idealerrepository;
}
public Dealers RegisterDealer(Guid id,string name,string tel,decimal telmoney,List<Contact>
contacts,Guid? parentid)
{
this.Id = id;
this.Code = "Code " + name;
this.Name = name;
this.Tel = tel;
this.TotalEleMoney = telmoney;
if (telmoney < )
{
this.CardType = CardType.普通会员;
}
else if (telmoney >= && telmoney < )
{
this.CardType = CardType.银卡会员;
}
else
{
this.CardType = CardType.金卡会员;
}
this.SubCount = ;
this.TotalPV = ;
this.JiangJInMoney = ;
this.Contacts = contacts;
this.DealerTree = new DealerTree(idealerrepository).CreateDealerTree(parentid, id);
return this;
}
}

7.登录聚合中登录对象的领域逻辑实现:

 public partial class Login
{
public Login CreateLogin(string code,Guid dealerid)
{
this.Id = Guid.NewGuid();
//手机号
this.Code = code;
//默认初始密码
this.Password=MD5Encrption.GetMd5Str("");
this.DealerId = dealerid;
return this;
}
}

这样,我们就完成了基本数据库的访问、操作和相关领域逻辑的实现。

QQ讨论群:309287205

DDD实战进阶视频请关注微信公众号:

最新文章

  1. Android音视频之MediaPlayer音视频播放
  2. mysql的Replication机制
  3. 利用ant脚本 自动构建svn增量/全量 系统程序升级包
  4. C#中 导入和导出Excel的方法
  5. Qt学习思考
  6. 为什么需要auto_ptr_ref
  7. Xcode磁盘空间大清理(转)
  8. Josephus2
  9. hdu1028:整数拆分
  10. [置顶] iOS学习笔记47——图片异步加载之EGOImageLoading
  11. stl 生产全排列 next_permutation
  12. java 将一个ip地址分割成一个数组
  13. 设计比较好,有助于学习的Github上的iOS App源码 (中文)
  14. 桥接模式-Bridge(Java实现)
  15. 自己对Java的一点看法
  16. D. Who killed Cock Robin 湖北省大学程序设计竞赛
  17. Import Projects from git
  18. 2018.06.27Firing(最大权闭合子图)
  19. jmeter响应信息unicode 编码转成中文
  20. 【thinkphp5】使用tp5开发api接口 定义全局异常处理

热门文章

  1. Hessian源码分析--HessianSkeleton
  2. FFmpeg API 变更记录
  3. Django练习——TodoList
  4. Linux多线程实践(9) --简单线程池的设计与实现
  5. OJ题:输入一个多位的数字,求各数位相加。
  6. JQuery实战总结三 标签页效果图实现
  7. android报错 Expected BEGIN_OBJECT but was STRING at line 1 column 39 path $
  8. 【一天一道LeetCode】#7. Reverse Integer
  9. Android服务器——使用TomCat实现软件的版本检测,升级,以及下载更新进度!
  10. ActiveMQ系列之三:理解和掌握JMS