public async Task <IActionResult> UpdateTouristRoute([FromRoute] Guid touristRouteId, [FromBody] TouristRouteForUpdateDto touristRouteForUpdateDto) { if (!(await _touristRouteRepository.TouristRouteExistsAsync(touristRouteId))) { return(NotFound("旅游路线不存在")); } var touristRouteFromRepo = await _touristRouteRepository.GetTouristRouteAsync(touristRouteId); _mapper.Map(touristRouteForUpdateDto, touristRouteFromRepo); await _touristRouteRepository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> Put([FromRoute] Guid touristRouteId, [FromBody] TouristRouteForUpdateDto touristRouteForUpdateDto) { if (!await _touristRouteRepository.TouristRouteExistsAsync(touristRouteId)) { return(NotFound($"找不到{touristRouteId}旅游路线")); } var touristRoute = await _touristRouteRepository.GetTouristRouteAsync(touristRouteId); _mapper.Map(touristRouteForUpdateDto, touristRoute); await _touristRouteRepository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> UpdateTouristRouteAsync( [FromRoute] Guid touristRouteId, [FromBody] TouristRouteForUpdateDto updateDto) { if (!(await touristRouteRepository.TouristRouteExistsAsync(touristRouteId))) { return(NotFound("旅游路线找不到")); } //映射dto 更新dto 映射model 实体模型追踪已更新 直接SaveChanges var touristRouteFromRepo = await touristRouteRepository.GetTouristRouteAsync(touristRouteId); mapper.Map(updateDto, touristRouteFromRepo); await touristRouteRepository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> UpdateTouristRoute( [FromRoute] Guid touristRouteId, [FromBody] TouristRouteForUpdateDto touristRouteForUpdateDto ) { if (!await _touristRouteRepository.TouristRouteExistsAsync(touristRouteId)) { return(NotFound($"旅游路线{touristRouteId}不存在")); } var touristRouteFromRepo = await _touristRouteRepository.GetTouristRouteAsync(touristRouteId); _mapper.Map(touristRouteForUpdateDto, touristRouteFromRepo); await _touristRouteRepository.SaveAsync(); var touristRouteToReturn = _mapper.Map <TouristRouteDto>(touristRouteFromRepo); return(Ok(touristRouteToReturn)); }
public async Task <IActionResult> UpdateTouristRouteAsync( [FromRoute] Guid touristRouteId, [FromBody] TouristRouteForUpdateDto touristRouteForUpdateDto ) { if (!await _touristRouteRepository.TouristRouteExistsAsync(touristRouteId)) { return(NotFound("旅遊路線找不到!")); } var touristRouteFromRepo = await _touristRouteRepository.GetTouristRouteAsync(touristRouteId); //1.映射dto //2.更新dto //3.映射model _mapper.Map(touristRouteForUpdateDto, touristRouteFromRepo); await _touristRouteRepository.SaveAsync(); return(NoContent()); }