private PlayedGame CreateTestPlayedGame( int gameDefinitionId, List <Player> players, List <int> correspondingPlayerRanks, ApplicationUser currentUser, IPlayedGameSaver playedGameSaver) { List <PlayerRank> playerRanks = new List <PlayerRank>(); for (int i = 0; i < players.Count(); i++) { playerRanks.Add(new PlayerRank { PlayerId = players[i].Id, GameRank = correspondingPlayerRanks[i] }); } NewlyCompletedGame newlyCompletedGame = new NewlyCompletedGame { GameDefinitionId = gameDefinitionId, PlayerRanks = playerRanks, }; return(playedGameSaver.CreatePlayedGame(newlyCompletedGame, TransactionSource.WebApplication, currentUser)); }
public virtual ActionResult Save(SavePlayedGameRequest request, ApplicationUser currentUser) { if (ModelState.IsValid) { int?resultId; if (request.EditMode && request.PlayedGameId.HasValue) { _playedGameSaver.UpdatePlayedGame( _mapperFactory.GetMapper <SavePlayedGameRequest, UpdatedGame>().Map(request), TransactionSource.WebApplication, currentUser); resultId = request.PlayedGameId; } else { if (request.GameDefinitionId == null) { if (string.IsNullOrEmpty(request.GameDefinitionName)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } request.GameDefinitionId = _gameDefinitionSaver.CreateGameDefinition(new CreateGameDefinitionRequest { Name = request.GameDefinitionName, GamingGroupId = request.GameDefinitionId ?? currentUser.CurrentGamingGroupId, BoardGameGeekGameDefinitionId = request.BoardGameGeekGameDefinitionId }, currentUser).Id; } foreach (var newPlayer in request.PlayerRanks.Where(p => !p.PlayerId.HasValue)) { newPlayer.PlayerId = _playerSaver.CreatePlayer(new CreatePlayerRequest { GamingGroupId = currentUser.CurrentGamingGroupId, Name = newPlayer.PlayerName }, currentUser).Id; } resultId = _playedGameSaver.CreatePlayedGame( _mapperFactory.GetMapper <SavePlayedGameRequest, NewlyCompletedGame>().Map(request), TransactionSource.WebApplication, currentUser).Id; } return(Json(new { success = true, playedGameId = resultId })); } return(Json(new { success = false, errors = ModelState.Errors() }, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage RecordPlayedGame([FromBody] PlayedGameMessage playedGameMessage, [FromUri] int gamingGroupId) { var newlyCompletedGame = transformer.Transform <NewlyCompletedGame>(playedGameMessage); var playedGame = playedGameSaver.CreatePlayedGame(newlyCompletedGame, TransactionSource.RestApi, CurrentUser); var newlyRecordedPlayedGameMessage = new NewlyRecordedPlayedGameMessage { PlayedGameId = playedGame.Id, GamingGroupId = playedGame.GamingGroupId }; return(Request.CreateResponse(HttpStatusCode.OK, newlyRecordedPlayedGameMessage)); }
private PlayedGame CreateTestPlayedGame( int gameDefinitionId, List<Player> players, List<int> correspondingPlayerRanks, ApplicationUser currentUser, IPlayedGameSaver playedGameSaver) { List<PlayerRank> playerRanks = new List<PlayerRank>(); for (int i = 0; i < players.Count(); i++) { playerRanks.Add(new PlayerRank { PlayerId = players[i].Id, GameRank = correspondingPlayerRanks[i] }); } NewlyCompletedGame newlyCompletedGame = new NewlyCompletedGame { GameDefinitionId = gameDefinitionId, PlayerRanks = playerRanks, }; return playedGameSaver.CreatePlayedGame(newlyCompletedGame, TransactionSource.WebApplication, currentUser); }