Exemplo n.º 1
0
        public async Task <ActionResult <VetDto> > AddVet([FromBody] VetForCreationDto vetForCreation)
        {
            var validationResults = new VetForCreationDtoValidator().Validate(vetForCreation);

            validationResults.AddToModelState(ModelState, null);

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

            var vet = _mapper.Map <Vet>(vetForCreation);
            await _vetRepository.AddVet(vet);

            var saveSuccessful = await _vetRepository.SaveAsync();

            if (saveSuccessful)
            {
                var vetFromRepo = await _vetRepository.GetVetAsync(vet.VetId);

                var vetDto   = _mapper.Map <VetDto>(vetFromRepo);
                var response = new Response <VetDto>(vetDto);

                return(CreatedAtRoute("GetVet",
                                      new { vetDto.VetId },
                                      response));
            }

            return(StatusCode(500));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <VetDto> > AddVet(VetForCreationDto vetForCreation)
        {
            var validationResults = new VetForCreationDtoValidator().Validate(vetForCreation);

            validationResults.AddToModelState(ModelState, null);

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

            var vet = _mapper.Map <Vet>(vetForCreation);

            _vetRepository.AddVet(vet);
            var saveSuccessful = await _vetRepository.SaveAsync();

            if (saveSuccessful)
            {
                var vetDto = await _vetRepository.GetVetAsync(vet.VetId); //get from repo for fk object, if needed

                return(CreatedAtRoute("GetVet",
                                      new { vetDto.VetId },
                                      vetDto));
            }

            return(StatusCode(500));
        }