public IActionResult UpdateNationalPark(int parkId, [FromBody] NationalParkDTO model) { if (model == null || parkId != model.Id) { return(BadRequest(ModelState)); } if (nationalParkRepository.NationalparkExit(model.Name)) { ModelState.AddModelError("", "This Park is already exist!"); return(StatusCode(404, ModelState)); } var data = mapper.Map <NationalPark>(model); if (!nationalParkRepository.UpdateNationalPark(data)) { ModelState.AddModelError("", $"Something is Wrong when Updating the park {data.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDTO nationalParkDTO) { if (nationalParkDTO == null || nationalParkId != nationalParkDTO.Id) { return(BadRequest(ModelState)); } var objName = npRepository.GetNationalPark(nationalParkDTO.Name); if (objName != null) { if (objName.Id != nationalParkId) { ModelState.AddModelError(string.Empty, "NationalPark Exists"); return(StatusCode(404, ModelState)); } } var obj = mapper.Map <NationalPark>(nationalParkDTO); var objFromDB = npRepository.GetNationalPark(obj.Id); objFromDB.Name = obj.Name; objFromDB.Id = obj.Id; objFromDB.State = obj.State; objFromDB.Established = obj.Established; objFromDB.Created = obj.Created; if (!npRepository.UpdateNationalPark(objFromDB)) { ModelState.AddModelError(string.Empty, $"SomeThing Wrong{obj.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto.Id != nationalParkId) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_nationalParkRepository.NationalParkExists(nationalParkId)) { ModelState.AddModelError("non-existing park", "Can't update a non-existing park"); return(BadRequest(ModelState)); } var nationalPark = _mapper.Map <NationalPark>(nationalParkDto); if (_nationalParkRepository.UpdateNationalPark(nationalPark)) { return(NoContent()); } ModelState.AddModelError("server error", "something went wrong while updating"); return(StatusCode(500, ModelState)); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || nationalParkId != nationalParkDto.Id) { return(BadRequest(ModelState)); } var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDto); if (!_npRepo.UpdateNationalPark(nationalParkObj)) { ModelState.AddModelError("", $"Something went wrong when updating the record {nationalParkObj.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || nationalParkId != nationalParkDto.Id) { return(BadRequest(ModelState)); } if (!_nationalParkRepository.UpdateNationalPark(_mapper.Map <NationalPark>(nationalParkDto))) { ModelState.AddModelError(String.Empty, $"Something went wrong while updating the record {nationalParkDto.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || nationalParkId != nationalParkDto.Id) { return(BadRequest(ModelState)); } var obj = _mapper.Map <NationalPark>(nationalParkDto); if (!_npRepo.UpdateNationalPark(obj)) { ModelState.AddModelError("", "cos poszlo nie tak przy zapisywaniu"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNatioanlPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || nationalParkId != nationalParkDto.id) { return(BadRequest(ModelState)); } var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDto); if (!_nationalParkRepository.UpdateNationalPark(nationalParkObj)) { ModelState.AddModelError("", $"Problem while updating the record {nationalParkDto.name}"); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || nationalParkId != nationalParkDto.Id) { return(BadRequest(ModelState)); } NationalPark nationalPark = _mapper.Map <NationalPark>(nationalParkDto); if (!_npRepo.UpdateNationalPark(nationalPark)) { ModelState.AddModelError("", $"Error with updating file {nationalPark.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int id, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto is null || id != nationalParkDto.Id) { return(BadRequest(ModelState)); } var park = _mapper.Map <NationalPark>(nationalParkDto); if (!_npRepo.UpdateNationalPark(park)) { ModelState.AddModelError("", "Something went wrong."); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDTO nationalParkDTO) { if (nationalParkDTO == null || nationalParkId != nationalParkDTO.Id) { return(BadRequest(ModelState)); } var nationalPark = _mapper.Map <NationalPark>(nationalParkDTO); if (!_nationalParkRepo.UpdateNationalPark(nationalPark)) { ModelState.AddModelError("", $"Something Went wrong while updating the {nationalParkDTO.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public async Task <IActionResult> UpdateNationalPark(int id, [FromBody] NationalParkDTO nationalParkDTO) { if (nationalParkDTO == null || nationalParkDTO.Id != id) { return(BadRequest(ModelState)); } var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDTO); if (!await _repo.UpdateNationalPark(nationalParkObj)) { ModelState.AddModelError("", $"Something went wrong when you are updating record {nationalParkObj.Name}"); return(StatusCode(500, ModelState)); } return(Ok(nationalParkObj)); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDTO nationalParkDTO) { if (nationalParkDTO == null || nationalParkId != nationalParkDTO.Id) { return(BadRequest(ModelState)); } var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDTO); if (!_nationalParkRepo.UpdateNationalPark(nationalParkObj)) { ModelState.AddModelError(CommonText.MSG_RESPONSE, $"Sảy ra lỗi khi update {nationalParkObj.Name}"); return(StatusCode(CommonText.SERVER_ERRORS, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto.Id != nationalParkId || nationalParkDto == null) { return(BadRequest(ModelState)); } var objToBd = _newParky.Map <NationalPark>(nationalParkDto); if (!_npRepo.UpdateNationalPark(objToBd)) { ModelState.AddModelError("", $"Some went when updating{objToBd.Name} "); return(StatusCode(500, ModelState)); } return(NoContent()); }
public async Task <IActionResult> UpdateNationalPark(int id, [FromBody] NationalParkDto dto) { if (dto == null || id != dto.Id) { return(BadRequest(ModelState)); } var nationalPark = _mapper.Map <NationalPark>(dto); if (await _repo.UpdateNationalPark(nationalPark) == false) { ModelState.AddModelError("", $"Something went wrong when updating the record {nationalPark.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDTO nationalParkDTO) { if (nationalParkDTO == null || nationalParkDTO.Id != nationalParkId) { return(BadRequest(ModelState)); } NationalPark nationalParkObj = _mapper.Map <NationalPark>(nationalParkDTO); if (!_npRepo.UpdateNationalPark(nationalParkObj)) { ModelState.AddModelError("", $"Something went wrong when updating the record {nationalParkObj.Name}"); return(StatusCode(500, ModelState)); } //return NoContent(); return(CreatedAtRoute("GetNationalPark", new { nationalParkId = nationalParkObj.Id }, nationalParkObj)); }
public IActionResult UpdateNationalPark(int nationalparkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || nationalparkId != nationalParkDto.Id) { return(BadRequest(ModelState)); } var domianObject = _mapper.Map <NationalPark>(nationalParkDto); if (!_repository.UpdateNationalPark(domianObject)) { ModelState.AddModelError(string.Empty, $"Updating record failed {domianObject.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || nationalParkId != nationalParkDto.Id) { return(BadRequest(ModelState));//ModelState contains errors if any are encountered } //We need to convert Dto to Domain Model var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDto); //If save was not successfull if (!_npRepo.UpdateNationalPark(nationalParkObj)) { ModelState.AddModelError("", $"Something went wrong when updating the record {nationalParkObj.Name}"); return(StatusCode(500, ModelState)); } //We dont return content as with a Create return(NoContent()); }
[HttpPatch("{parkId:int}", Name = "UpdateNationalPark")] // dont add space in value public IActionResult UpdateNationalPark(int parkId, [FromBody] NationalParkDTO parkDto) { if (parkDto == null || parkDto.Id != parkId) { return(BadRequest(ModelState)); } // add more validation like existense var parkObj = _mapper.Map <NationalPark>(parkDto); if (!_npRepo.UpdateNationalPark(parkObj)) { ModelState.AddModelError("", $"Something went wrong when updating {parkObj.Name }"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int natId, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || natId != nationalParkDto.Id) { return(BadRequest(ModelState)); } if (!_npRepo.NationalParkExists(natId)) { ModelState.AddModelError("", "National Park Does Not Exist!"); return(StatusCode(404, ModelState)); } var objToBeUpdated = _mapper.Map <NationalParkDto, NationalPark>(nationalParkDto); if (!_npRepo.UpdateNationalPark(objToBeUpdated)) { ModelState.AddModelError("", $"something went wrong updating the record {objToBeUpdated.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int id, [FromBody] NationalParkDTO nationalParkDTO) { if (nationalParkDTO == null || nationalParkDTO.Id != id) { return(BadRequest(new { message = "Data could not be found!" })); } var nationalPark = _mapper.Map <NationalPark>(nationalParkDTO); var succeed = _npRepository.UpdateNationalPark(nationalPark); if (succeed) { return(Ok(new { message = "Data is successfully updated!" })); } else { return(BadRequest(new { message = "Data could not be updated!" })); } }
[ProducesResponseType(StatusCodes.Status500InternalServerError)] // 5. Part 8 public IActionResult UpdateNationalPark(int nationalParkId, [FromBody] NationalParkUpdateDto nationalParkUpdateDto) { if (nationalParkUpdateDto == null || nationalParkId != nationalParkUpdateDto.Id) { return(BadRequest()); } if (!npRepository.NationalParkExists(nationalParkId)) { return(NotFound()); } var nationalPark = mapper.Map <NationalPark>(nationalParkUpdateDto); if (!npRepository.UpdateNationalPark(nationalPark)) { ModelState.AddModelError("", $"Something went wrong, when updating the record {nationalPark.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateNationalPark(int id, [FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null || id != nationalParkDto.Id) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDto); if (!_repo.UpdateNationalPark(nationalParkObj)) { ModelState.AddModelError("", $"Problem was occurred during updating {nationalParkDto.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }