Beispiel #1
0
        public async Task <ActionResult <PatientDto> > AddPatient([FromBody] PatientForCreationDto patientForCreation)
        {
            var validationResults = new PatientForCreationDtoValidator().Validate(patientForCreation);

            validationResults.AddToModelState(ModelState, null);

            if (!ModelState.IsValid)
            {
                return(BadRequest(new ValidationProblemDetails(ModelState)));
                //return ValidationProblem();
            }

            var patient = _mapper.Map <Patient>(patientForCreation);
            await _patientRepository.AddPatient(patient);

            var saveSuccessful = await _patientRepository.SaveAsync();

            if (saveSuccessful)
            {
                var patientFromRepo = await _patientRepository.GetPatientAsync(patient.PatientId);

                var patientDto = _mapper.Map <PatientDto>(patientFromRepo);
                var response   = new Response <PatientDto>(patientDto);

                return(CreatedAtRoute("GetPatient",
                                      new { patientDto.PatientId },
                                      response));
            }

            return(StatusCode(500));
        }
Beispiel #2
0
        public async Task <IActionResult> CreatePatient(string id, [FromBody] PatientForCreationDto patientForCreation)
        {
            var userFromRepo = await _userManager.Users.FirstOrDefaultAsync(u => u.Id == id);

            if (userFromRepo == null)
            {
                return(BadRequest(new { Message = "User doesn't exist." }));
            }

            var patientFromRepo = await _repository.Patient.FindByCondition(p => p.Id == id).FirstOrDefaultAsync();

            if (patientFromRepo != null)
            {
                return(BadRequest(new { Message = "Patient already exist." }));
            }

            var patient = _mapper.Map <Patient>(patientForCreation);

            patient.Id = id;

            _repository.Patient.Create(patient);
            _repository.SaveAsync();

            return(CreatedAtRoute("GetPatient", new { id }, patient));
        }
        public async Task <ActionResult <PatientDto> > AddPatient([FromBody] PatientForCreationDto patientForCreation)
        {
            // add error handling
            var command         = new AddPatientCommand(patientForCreation);
            var commandResponse = await _mediator.Send(command);

            var response = new Response <PatientDto>(commandResponse);

            return(CreatedAtRoute("GetPatient",
                                  new { commandResponse.PatientId },
                                  response));
        }
        public async Task <IActionResult> AddPatient([FromBody] PatientForCreationDto patientForCreation, CancellationToken cancellationToken)
        {
            try
            {
                var creationCommand = new PatientForCreationCommand(patientForCreation);
                var patientDto      = await _mediator.Send(creationCommand, cancellationToken);

                var response = new Response <PatientDto>(patientDto);

                return(CreatedAtRoute("GetPatient",
                                      new { patientDto.PatientId },
                                      response));
            }
            catch (Exception e)
            {
                // add a specific catch for Notfound
                return(StatusCode(500));
            }
        }
 public AddPatientCommand(PatientForCreationDto patientToAdd)
 {
     PatientToAdd = patientToAdd;
 }
Beispiel #6
0
 public PatientForCreationCommand(PatientForCreationDto patientForCreationDto)
 {
     CreationCommand = patientForCreationDto;
 }