public Task <Unit> Handle(RemoveOfficeCommand request, CancellationToken cancellationToken) { // 命令验证 if (!request.IsValid()) { // 错误信息收集 NotifyValidationErrors(request); return(Task.FromResult(new Unit())); } // 实例化领域模型,这里才真正的用到了领域模型 // 注意这里是通过构造函数方法实现 Office office = request.MapTo <Office>(); // 判断组织机构编码或名称是否存在 if (_officeRepository.GetAll(x => x.ParentId == request.Id).Any()) { _bus.RaiseEvent(new DomainNotification("", "组织机构存在子级,不允许删除!")); return(Task.FromResult(new Unit())); } _officeRepository.Update(office); // 统一提交 if (Commit()) { OfficeRemovedEvent officeCreatedEvent = new OfficeRemovedEvent(request.Id, request.DelFlag, request.Remark?.Trim(), request.UpdateDate.Value, request.UpdateBy.Value); _bus.RaiseEvent(officeCreatedEvent); } return(Task.FromResult(new Unit())); }
public Task RemoveOffice([FromBody] RemoveOfficeCommand command) { return(Mediator.Send(command)); }