Exemplo n.º 1
0
        public async Task <IActionResult> Put([FromBody] TownUpdateModel townUpdateModel)
        {
            TownDto townDto = await _townService.GetTown(townUpdateModel.TownId);

            if (townDto == null)
            {
                return(NotFound($"No such town with id: {townUpdateModel.TownId}"));
            }
            if (townDto.Title != townUpdateModel.Title && await _townService.Exists(townUpdateModel.Title))
            {
                return(Conflict($"Such town already exists with title {townUpdateModel.Title} "));
            }
            TownDto townCreateDto  = _mapper.Map <TownDto>(townUpdateModel);
            TownDto updatedTownDto = await _townService.UpdateTown(townCreateDto);

            TownWebModel updatedTownModel = _mapper.Map <TownWebModel>(updatedTownDto);

            return(CreatedAtAction(nameof(Get), new { id = updatedTownModel.TownId }, updatedTownModel));
        }