public async Task <ActionResult <LeagueSeason> > PostLeagueSeason(LeagueSeasonModel model) { try { var location = _linkGenerator.GetPathByAction("GetLeagueSeason", "LeagueSeasons", new { id = -1 }); if (string.IsNullOrWhiteSpace(location)) { return(BadRequest("Could not use ID")); } var leagueSeason = _mapper.Map <LeagueSeason>(model); await _leagueSeasonRepository.AddAsync(leagueSeason); if (await _sharedRepository.SaveChangesAsync() > 0) { return(Created(location, _mapper.Map <LeagueSeasonModel>(leagueSeason))); } return(BadRequest()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, Settings.DatabaseFailureString)); } }
public async Task <IActionResult> Create([Bind("LeagueName,SeasonYear,TotalGames,TotalPoints,AveragePoints")] LeagueSeason leagueSeason) { if (ModelState.IsValid) { await _leagueSeasonRepository.AddAsync(leagueSeason); await _sharedRepository.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(leagueSeason)); }