public override async Task <ActionResult <UpdatePatientResponse> > HandleAsync(UpdatePatientRequest request, CancellationToken cancellationToken) { var response = new UpdatePatientResponse(request.CorrelationId); var spec = new ClientByIdIncludePatientsSpec(request.ClientId); var client = await _repository.GetBySpecAsync(spec); if (client == null) { return(NotFound()); } var patientToUpdate = client.Patients.FirstOrDefault(p => p.Id == request.PatientId); if (patientToUpdate == null) { return(NotFound()); } patientToUpdate.Name = request.Name; await _repository.UpdateAsync(client); var dto = _mapper.Map <PatientDto>(patientToUpdate); 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 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 async Task AddsPatientAndSetsId() { var client = await AddClient(); var patient = client.Patients.First(); var clientWithPatientsSpec = new ClientByIdIncludePatientsSpec(client.Id); var clientFromDb = await _repository.GetBySpecAsync(clientWithPatientsSpec); var newPatient = clientFromDb.Patients.First(); Assert.Equal(patient, newPatient); Assert.True(newPatient?.Id > 0); }
public override async Task <ActionResult <ListPatientResponse> > HandleAsync([FromQuery] ListPatientRequest request, CancellationToken cancellationToken) { var response = new ListPatientResponse(request.CorrelationId); var spec = new ClientByIdIncludePatientsSpec(request.ClientId); var client = await _repository.GetBySpecAsync(spec); if (client == null) { return(NotFound()); } response.Patients = _mapper.Map <List <PatientDto> >(client.Patients); response.Count = response.Patients.Count; return(Ok(response)); }
public override async Task <ActionResult <DeletePatientResponse> > HandleAsync([FromRoute] DeletePatientRequest request, CancellationToken cancellationToken) { var response = new DeletePatientResponse(request.CorrelationId()); var spec = new ClientByIdIncludePatientsSpec(request.ClientId); var client = await _repository.GetBySpecAsync(spec); if (client == null) { return(NotFound()); } var patientToDelete = client.Patients.FirstOrDefault(p => p.Id == request.PatientId); client.Patients.Remove(patientToDelete); await _repository.UpdateAsync(client); return(Ok(response)); }
public override async Task <ActionResult <GetByIdPatientResponse> > HandleAsync([FromRoute] GetByIdPatientRequest request, CancellationToken cancellationToken) { var response = new GetByIdPatientResponse(request.CorrelationId()); var spec = new ClientByIdIncludePatientsSpec(request.ClientId); var client = await _repository.GetBySpecAsync(spec); if (client == null) { return(NotFound()); } var patient = client.Patients.FirstOrDefault(p => p.Id == request.PatientId); if (patient == null) { return(NotFound()); } response.Patient = _mapper.Map <PatientDto>(patient); return(Ok(response)); }