public virtual ActionResult Create(CreateGameDefinitionViewModel createGameDefinitionViewModel, ApplicationUser currentUser)
        {
            if (ModelState.IsValid)
            {
                createGameDefinitionViewModel.Name = createGameDefinitionViewModel.Name.Trim();
                var createGameDefinitionRequest = Mapper.Map <CreateGameDefinitionViewModel, CreateGameDefinitionRequest>(createGameDefinitionViewModel);

                var savedResult = _createGameDefinitionComponent.Execute(createGameDefinitionRequest, currentUser);

                if (!string.IsNullOrWhiteSpace(createGameDefinitionViewModel.ReturnUrl))
                {
                    return(new RedirectResult(createGameDefinitionViewModel.ReturnUrl + "?gameId=" + savedResult.Id));
                }

                return(new RedirectResult(Url.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name)
                                          + "#" + GamingGroupController.SECTION_ANCHOR_GAMEDEFINITIONS));
            }

            return(View(MVC.GameDefinition.Views.Create, createGameDefinitionViewModel));
        }
Ejemplo n.º 2
0
        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 = _createGameDefinitionComponent.Execute(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;
                    }

                    var newlyCompletedGame = _mapperFactory.GetMapper <SavePlayedGameRequest, NewlyCompletedGame>().Map(request);
                    newlyCompletedGame.TransactionSource = TransactionSource.WebApplication;
                    resultId =
                        _createPlayedGameComponent.Execute(newlyCompletedGame, currentUser).Id;
                }


                return(Json(new { success = true, playedGameId = resultId }));
            }

            return(Json(new { success = false, errors = ModelState.Errors() }, JsonRequestBehavior.AllowGet));
        }
        public virtual HttpResponseMessage SaveNewGameDefinition([FromBody]NewGameDefinitionMessage newGameDefinitionMessage, [FromUri]int gamingGroupId)
        {
            var createGameDefinitionRequest = new CreateGameDefinitionRequest
            {
                BoardGameGeekGameDefinitionId = newGameDefinitionMessage.BoardGameGeekObjectId,
                Name = newGameDefinitionMessage.GameDefinitionName,
                GamingGroupId = newGameDefinitionMessage.GamingGroupId ?? gamingGroupId
            };

            var newGameDefinition = _createGameDefinitionComponent.Execute(createGameDefinitionRequest, CurrentUser);

            var newlyCreatedGameDefinitionMessage = new NewlyCreatedGameDefinitionMessage
            {
                GameDefinitionId = newGameDefinition.Id,
                GamingGroupId = newGameDefinition.GamingGroupId
            };

            return Request.CreateResponse(HttpStatusCode.OK, newlyCreatedGameDefinitionMessage);
        }
Ejemplo n.º 4
0
        private void CreateGameDefinitions(ApplicationUser applicationUser, List <GameDetails> pendingGames, int gamesImported, dynamic longRunningClients,
                                           List <string> gameNamesImported)
        {
            foreach (var bggGame in pendingGames)
            {
                var gameName = $"{bggGame.Name} ({bggGame.YearPublished})";
                gamesImported++;

                longRunningClients.BGGImportDetailsProgress(gamesImported, pendingGames.Count, gameName);

                if (!gameNamesImported.Contains(gameName))
                {
                    _createGameDefinitionComponent.Execute(new CreateGameDefinitionRequest
                    {
                        Name = $"{bggGame.Name} ({bggGame.YearPublished})",
                        BoardGameGeekGameDefinitionId = bggGame.GameId,
                        Active = true
                    }, applicationUser);
                }

                gameNamesImported.Add(gameName);
            }
        }