Пример #1
0
        public async Task <IActionResult> Put(int id, SaveClinicDto clinicDto)
        {
            var validator        = new SaveClinicResourceValidator();
            var validationResult = await validator.ValidateAsync(clinicDto);

            var requestIsInvalid = id == 0 || !validationResult.IsValid;

            if (requestIsInvalid)
            {
                return(BadRequest(validationResult.Errors));
            }

            if (!ClinicExists(id))
            {
                return(NotFound());
            }

            var clinic = _mapper.Map <SaveClinicDto, Clinic>(clinicDto);

            try
            {
                await _clinicService.UpdateClinic(id, clinic);

                var updatedClinic = await _clinicService.GetClinicById(id);

                var updatedClinicResource = _mapper.Map <Clinic, ClinicDto>(updatedClinic);

                return(Ok(updatedClinicResource));
            }
            catch (Exception)
            {
                throw new Exception(StatusCodes.Status500InternalServerError.ToString());
            }
        }
Пример #2
0
        public async Task <ActionResult <ClinicDto> > Post(SaveClinicDto clinicDto)
        {
            var validator        = new SaveClinicResourceValidator();
            var validationResult = await validator.ValidateAsync(clinicDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var clinicToCreate = _mapper.Map <SaveClinicDto, Clinic>(clinicDto);

            var newClinic = await _clinicService.CreateClinic(clinicToCreate);

            var clinic = await _clinicService.GetClinicById(newClinic.Id);

            var clinicResource = _mapper.Map <Clinic, ClinicDto>(clinic);

            return(Ok(clinicResource));
        }