public async Task <IActionResult> Edit(StadiumViewModel stadiumViewModel) { if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "Data is not valid"); stadiumViewModel.CountriesItems = countryService.GetAllAsKeyValuePairs(); return(View(stadiumViewModel)); } try { await stadiumService.UpdateAsync(stadiumViewModel); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.InnerException?.Message ?? ex.Message); stadiumViewModel.CountriesItems = countryService.GetAllAsKeyValuePairs(); return(View(stadiumViewModel)); } TempData["SuccessMessage"] = $"Stadium {stadiumViewModel.Name} updated successfully."; return(RedirectToAction("Index")); }
public async Task <IActionResult> UpdateStadium(int id, [FromBody] StadiumUpdateDto stadiumUpdateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var stadium = await _stadiumService.GetByIdAsync(id); if (stadium == null) { return(NotFound()); } _mapper.Map(stadiumUpdateDto, stadium); await _stadiumService.UpdateAsync(stadium); var updatedStadium = await _stadiumService.GetByIdAsync(id); var returnStadium = _mapper.Map <StadiumDetailDto>(updatedStadium); return(Ok(returnStadium)); }