Exemplo n.º 1
0
        public IActionResult UpdateDogInformation(int clientId, int id,
                                                  [FromBody] DogForUpdateDto dog)
        {
            if (dog.Name == dog.ShortName)
            {
                ModelState.AddModelError(
                    "ShortName",
                    "The Name and Short Name cannot be the same (please use less characters with short name field)");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_clientInfoRepository.ClientExists(clientId))
            {
                return(NotFound());
            }

            var dogEntity = _clientInfoRepository
                            .GetDogForClient(clientId, id);

            if (dogEntity == null)
            {
                return(NotFound());
            }

            _mapper.Map(dog, dogEntity);

            _clientInfoRepository.UpdateDogInformationForClient(clientId, dogEntity);

            _clientInfoRepository.Save();

            return(NoContent());
        }