public IActionResult Team() { var teams = _TeamscoreContext.Teams.Include("Member"); var matches = _TeamscoreContext.Matches.Include(t => t.Team1Id).Include(t => t.Team2Id); if (teams == null) { return(NotFound()); } List <ExportTeam> ExportTeams = new List <ExportTeam>(); foreach (var team in teams) { ExportTeam e_team = new ExportTeam(team.TeamId, team.Name, team.Member.MemberId, team.Member.Name, 0); ExportTeams.Add(e_team); } int teamScore; foreach (var team in ExportTeams) { teamScore = 0; foreach (var match in matches) { if (match.Team1Id.TeamId == team.TeamId && match.ScoreTeam1 > match.ScoreTeam2) { teamScore += match.ScoreTeam1 + 10; } else if (match.Team1Id.TeamId == team.TeamId && match.ScoreTeam1 < match.ScoreTeam2) { teamScore += match.ScoreTeam1 + 5; } if (match.Team2Id.TeamId == team.TeamId && match.ScoreTeam2 > match.ScoreTeam1) { teamScore += match.ScoreTeam2 + 10; } else if (match.Team2Id.TeamId == team.TeamId && match.ScoreTeam2 < match.ScoreTeam1) { teamScore += match.ScoreTeam2 + 5; } } team.TeamScore = teamScore; } var json = JsonConvert.SerializeObject(ExportTeams); return(Ok(json)); }
public IActionResult Create([FromBody] ExportTeam item) { if (item == null) { return(BadRequest()); } var member = _TeamscoreContext.Members.Where(m => m.MemberId == item.MemberId).First(); if (member == null) { return(BadRequest("Member doesnt Exist")); } Team team = new Team() { TeamId = 0, Name = item.Name, Member = member }; _TeamscoreContext.Teams.Add(team); _TeamscoreContext.SaveChanges(); return(Ok(item)); }