Exemple #1
0
        public async Task <IActionResult> UpdateSightAsync(int id, [FromBody] SightUpdateDto sightUpdateDto)
        {
            try
            {
                if (sightUpdateDto == null)
                {
                    return(BadRequest());
                }

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

                await _sightService.UpdateSightAsync(id, sightUpdateDto);

                return(Ok());
            }
            catch (ObjectNotFoundException ex)
            {
                _logger.LogInformation(ex.Message);
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemple #2
0
        public async Task <ActionResult> Put(Guid townId, Guid id, [FromBody] SightUpdateDto sightUpdateDto)
        {
            // null check
            if (townId == null || id == null || sightUpdateDto == null)
            {
                return(BadRequest());
            }

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

            // retrieve the sight
            var sight = await Repository.GetSightAsync(townId, id);

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

            Mapper.Map(sightUpdateDto, sight);

            // call the repository
            await Repository.UpdateSightAsync(sight);

            return(NoContent());
        }
Exemple #3
0
        public async Task UpdateSightAsync(int id, SightUpdateDto sightUpdateDto)
        {
            var existingSight = await _sightsRepository.FindByIdAsync(id);

            if (existingSight == null)
            {
                throw new ObjectNotFoundException($"Sight with id {id} does not exist");
            }
            await _sightsRepository.UpdateAsync(id, _mapper.Map <Sight>(sightUpdateDto));
        }