예제 #1
0
 //TODO: All these methods should move to a dedicated service
 public async Task <PostScoreViewModel> Save(League league, Db db)
 {
     if (!BluePlayer.IsNoE() && !RedPlayer.IsNoE())
     {
         await SavePlayerScore(league, db);
     }
     else
     {
         await SaveTeamScore(league, db);
     }
     return(this);
 }
예제 #2
0
        private async Task SavePlayerScore(League league, Db db)
        {
            if (BluePlayerScore <= 0 && RedPlayerScore <= 0)
            {
                throw new Exception("Invalid scores, both must be greater zero.");
            }
            if (BluePlayer.IsNoE() || RedPlayer.IsNoE())
            {
                throw new Exception("One or more player names empty.");
            }

            var bluePlayer = await GetOrCreatePlayer(BluePlayer, league, db);

            var redPlayer = await GetOrCreatePlayer(RedPlayer, league, db);

            var game = await CreateGame(RedPlayerScore, BluePlayerScore, league, db);

            await CreatePosition(game, redPlayer, PlayerPositionTypes.Red, db);
            await CreatePosition(game, bluePlayer, PlayerPositionTypes.Blue, db);
        }