public override async Task <ActionResult <CreatePatientResponse> > HandleAsync(CreatePatientRequest request, CancellationToken cancellationToken) { var response = new CreatePatientResponse(request.CorrelationId); var spec = new ClientByIdIncludePatientsSpec(request.ClientId); var client = await _repository.GetBySpecAsync(spec); if (client == null) { return(NotFound()); } // right now we only add huskies var newPatient = new Patient { ClientId = client.Id, Name = request.PatientName, AnimalType = new AnimalType("Dog", "Husky") }; client.Patients.Add(newPatient); await _repository.UpdateAsync(client); var dto = _mapper.Map <PatientDto>(newPatient); response.Patient = dto; return(Ok(response)); }
public override async Task <ActionResult <CreatePatientResponse> > HandleAsync(CreatePatientRequest request, CancellationToken cancellationToken) { var response = new CreatePatientResponse(request.CorrelationId()); var spec = new ClientByIdIncludePatientsSpecification(request.ClientId); var client = await _repository.GetAsync <Client, int>(spec); if (client == null) { return(NotFound()); } var newPatient = new Patient(client.Id, request.PatientName, "", new Core.ValueObjects.AnimalType("Dog", "Husky")); client.Patients.Add(newPatient); await _repository.UpdateAsync <Client, int>(client); var dto = _mapper.Map <PatientDto>(newPatient); response.Patient = dto; return(Ok(response)); }