public HttpResponseMessage UpdatePlayedGame([FromBody] UpdatedPlayedGameMessage playedPlayedGameMessage)
        {
            var newlyCompletedGame = _transformer.Transform <UpdatedGame>(playedPlayedGameMessage);

            _playedGameSaver.UpdatePlayedGame(newlyCompletedGame, TransactionSource.RestApi, CurrentUser);

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
        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));
        }