Exemple #1
0
        public IActionResult UpdateDogForOwner(int ownerId, int dogId, DogForUpdateDto dog)
        {
            if (!_ownerRepository.OwnerExists(ownerId))
            {
                return(NotFound());
            }

            var dogFromRepo = _dogRepository.GetDogByOwner(ownerId, dogId);

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

            _mapper.Map(dog, dogFromRepo);
            _dogRepository.UpdateDog(dogFromRepo);
            return(NoContent());
        }
Exemple #2
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());
        }