示例#1
0
        public override async Task <ActionResult <CreateDoctorResponse> > HandleAsync(CreateDoctorRequest request, CancellationToken cancellationToken)
        {
            var response = new CreateDoctorResponse(request.CorrelationId());

            var toAdd = _mapper.Map <Doctor>(request);

            toAdd = await _repository.AddAsync <Doctor, int>(toAdd);

            var dto = _mapper.Map <DoctorDto>(toAdd);

            response.Doctor = dto;

            return(Ok(response));
        }
        public override async Task <ActionResult <CreateDoctorResponse> > HandleAsync(CreateDoctorRequest request, CancellationToken cancellationToken)
        {
            var response = new CreateDoctorResponse(request.CorrelationId());

            var toAdd = _mapper.Map <Doctor>(request);

            toAdd = await _repository.AddAsync(toAdd);

            var dto = _mapper.Map <DoctorDto>(toAdd);

            response.Doctor = dto;

            // Note: These messages could be triggered from the Repository or DbContext events
            // In the DbContext you could look for entities marked with an interface saying they needed
            // to be synchronized via cross-domain events and publish the appropriate message.
            var appEvent = new EntityCreatedEvent(_mapper.Map <NamedEntity>(toAdd));

            _messagePublisher.Publish(appEvent);

            return(Ok(response));
        }