public Task <Unit> Handle(UpdateOfficeCommand request, CancellationToken cancellationToken) { // 命令验证 if (!request.IsValid()) { // 错误信息收集 NotifyValidationErrors(request); return(Task.FromResult(new Unit())); } // 实例化领域模型,这里才真正的用到了领域模型 // 注意这里是通过构造函数方法实现 Office old_office = _officeRepository.GetById(request.Id); Office office = request.MapTo(old_office); // 判断组织机构编码或名称是否存在 // 这些业务逻辑,当然要在领域层中(领域命令处理程序中)进行处理 if (_officeRepository.GetAll(x => x.OfficeCode == request.OfficeCode || x.OfficeName.Equals(request.OfficeName)).Any()) { _bus.RaiseEvent(new DomainNotification("", "组织机构编号或名称已经存在!")); return(Task.FromResult(new Unit())); } _officeRepository.Add(office); // 统一提交 if (Commit()) { OfficeUpdatedEvent officUpdatedEvent = new OfficeUpdatedEvent(request.Id, request.OfficeName.Trim(), request.OfficePhone?.Trim(), request.OfficeCode?.Trim(), request.OfficeType, request.ParentId, request.ParentIds?.Trim(), request.DelFlag, request.Remark?.Trim(), request.UpdateDate.Value, request.UpdateBy.Value); _bus.RaiseEvent(officUpdatedEvent); } return(Task.FromResult(new Unit())); }
public Task Handle(OfficeUpdatedEvent notification, CancellationToken cancellationToken) { return(Task.CompletedTask); }