Ejemplo n.º 1
0
        public static Score GetScore(Game game)
        {
            var homeTeamPlayers = game.HomeTeam.Players.Select(player => player.Id);
            var awayTeamPlayers = game.AwayTeam.Players.Select(player => player.Id);

            var score = new Score {
                HomeTeamScore = game.Goals
                    .Where(goal => homeTeamPlayers.Contains(goal.Player.Id))
                    .Sum(goal => goal.Count),
                AwayTeamScore = game.Goals
                    .Where(goal => awayTeamPlayers.Contains(goal.Player.Id))
                    .Sum(goal => goal.Count)
            };

            if (score.IsTie) {
                return score;
            }

            score.WinningTeamId = score.HomeTeamScore > score.AwayTeamScore
                ? game.HomeTeam.Id
                : game.AwayTeam.Id;

            score.LosingTeamId = score.HomeTeamScore < score.AwayTeamScore
                ? game.HomeTeam.Id
                : game.AwayTeam.Id;

            return score;
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> Post([FromBody] Game game) {
            var newGame = new Game {
                AwayTeam = null,
                AwayTeamId = game.AwayTeam.Id,
                HomeTeam = null,
                HomeTeamId = game.HomeTeam.Id,
                Date = game.Date,
                DivisionId = game.DivisionId,
                Location = null,
                LocationId = game.Location.Id
            };

            _db.Games.Add(newGame);

            await _db.SaveChangesAsync();

            game.Id = newGame.Id;

            return CreatedAtRoute("GetSingleGame", new { id = game.Id }, game);
        }
Ejemplo n.º 3
0
        public async Task<IHttpActionResult> Delete(int id) {
            var game = new Game { Id = id };

            _db.Games.Remove(game);
            await _db.SaveChangesAsync();

            return StatusCode(HttpStatusCode.NoContent);
        }