public IActionResult OnPostEnterTeam([FromBody] AddTeamRequest addTeamRequest) { try { if (addTeamRequest.RaceId == 0) { throw new Exception("Invalid Race"); } var teamId = GetNextTeamId(addTeamRequest.RaceId); foreach (int racerId in addTeamRequest.RacerIds) { var result = new WLC.Models.Results() { Place = 4, TeamId = teamId, RaceId = addTeamRequest.RaceId, RacerId = racerId, Year = Globals.GetActiveYear(HttpContext) }; _context.Results.Add(result); } _context.SaveChanges(); return(new JsonResult(new { error = false, message = "RacerAdded" })); } catch (Exception ex) { return(new JsonResult(new { error = true, message = "Adding Team Failed: " + ex.Message })); } }
public IActionResult OnGetEnterRacer([FromQuery] int racerId, int raceId) { try { if (racerId == 0) { throw new Exception("Invalid Race"); } var result = new WLC.Models.Results() { Place = 4, TeamId = GetNextTeamId(raceId), RaceId = raceId, RacerId = racerId, Year = Globals.GetActiveYear(HttpContext) }; _context.Results.Add(result); _context.SaveChanges(); return(new JsonResult(new { error = false, message = "RacerAdded" })); } catch (Exception ex) { return(new JsonResult(new { error = true, message = "Adding Racer Failed: " + ex.Message })); } }