public IActionResult CreateLeague([FromBody] LeagueCreateModel leagueCreateModel) { if (leagueCreateModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var leagueEntity = _mapper.Map <League>(leagueCreateModel); _leagueRepository.AddLeague(leagueEntity); if (!_mlbDraftRepository.Save()) { throw new Exception("Creating a league failed on save."); } var leagueToReturn = _mapper.Map <LeagueModel>(leagueEntity); return(CreatedAtRoute("GetLeague", new League { Id = leagueToReturn.Id }, leagueToReturn)); }
public IActionResult Post([FromBody] LeagueForCreationDto league) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (league == null) { return(BadRequest()); } var leagueEntity = Mapper.Map <League>(league); _leagueRepository.AddLeague(leagueEntity); if (!_leagueRepository.Save()) { throw new Exception("Creating an league failed on save."); } var leagueToReturn = Mapper.Map <LeagueDto>(leagueEntity); return(CreatedAtRoute("GetLeague", new { id = leagueToReturn.LeagueId }, leagueToReturn)); }
public void AddLeague(League league) { if (GetAllLeagues().Count != 0) { league.Id = GetAllLeagues().LastOrDefault().Id + 1; } else { league.Id = 1; } _leaguerepo.AddLeague(league); }