Beispiel #1
0
        public async Task <IActionResult> CreateAppointmentAsync(
            [FromBody] CreateAppointmentRequestDto createAppointmentRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var validationResult = await _createAppointmentRequestDtoValidator.ValidateAsync(createAppointmentRequestDto, token);

                if (!validationResult.IsValid)
                {
                    return(new BadRequestObjectResult(validationResult.Errors.ToValidationErrors()));
                }

                var appointmentServiceObject = Mapper.Map <AppointmentServiceObject>(createAppointmentRequestDto);
                var serviceResponse          = await _appointmentService.CreateAppointmentAsync(appointmentServiceObject, token);

                return(new CreatedResult(string.Empty, Mapper.Map <CreateAppointmentResponseDto>(serviceResponse)));
            }
            catch (BadRequestException e)
            {
                return(new BadRequestObjectResult(e.Error));
            }
        }