public async Task <ActionResult <TeamSeason> > PostTeamSeason(TeamSeasonModel model) { try { var location = _linkGenerator.GetPathByAction("GetTeamSeason", "TeamSeasons", new { id = -1 }); if (string.IsNullOrWhiteSpace(location)) { return(BadRequest("Could not use ID")); } var teamSeason = _mapper.Map <TeamSeason>(model); await _teamSeasonRepository.AddAsync(teamSeason); if (await _sharedRepository.SaveChangesAsync() > 0) { return(Created(location, _mapper.Map <TeamSeasonModel>(teamSeason))); } return(BadRequest()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, Settings.DatabaseFailureString)); } }
public async Task <IActionResult> Create([Bind("TeamName,SeasonYear,LeagueName")] TeamSeason teamSeason) { if (ModelState.IsValid) { await _teamSeasonRepository.AddAsync(teamSeason); await _sharedRepository.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(teamSeason)); }