public async Task <IActionResult> Create(StadiumViewModel stadiumViewModel) { if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "Data is not valid"); stadiumViewModel.CountriesItems = countryService.GetAllAsKeyValuePairs(); return(View(stadiumViewModel)); } try { await stadiumService.CreateAsync(stadiumViewModel); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.InnerException?.Message ?? ex.Message); stadiumViewModel.CountriesItems = countryService.GetAllAsKeyValuePairs(); return(View(stadiumViewModel)); } TempData["SuccessMessage"] = "Stadium added successfully."; return(RedirectToAction("Index")); }
public async Task <IActionResult> CreateStadium([FromBody] StadiumCreateDto stadiumCreateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var stadiumToCreate = _mapper.Map <Stadium>(stadiumCreateDto); await _stadiumService.CreateAsync(stadiumToCreate); var stadium = await _stadiumService.GetByIdAsync(stadiumToCreate.Id); var returnStadium = _mapper.Map <StadiumDetailDto>(stadium); return(Ok(returnStadium)); }