Ejemplo n.º 1
0
        public ActionResult CreateGame(CreateGameViewModel model)
        {
            var game = Mapper.Map <CreateGameViewModel, Game>(model);

            if (model.SelectedPlatforms.Any())
            {
                game.Platforms = _platformManager.Find(x => model.SelectedPlatforms.Any(f => f == x.Id)).ToList();
            }

            if (model.SelectedGenres.Any())
            {
                game.Genres = _genreManager.Find(x => model.SelectedGenres.Any(f => f == x.Id)).ToList();
            }

            if (model.SelectedPublishers.Any())
            {
                game.Publishers = _publisherManager.Find(x => model.SelectedPublishers.Any(f => f == x.Id)).ToList();
            }

            game.AddingDate = DateTime.UtcNow;
            var request = _gameManager.CreateNewGame(game);

            if (request != HttpStatusCode.Created)
            {
                throw new ValidationException("Invalid form data.");
            }

            return(RedirectToAction("GetAllGames"));
        }
Ejemplo n.º 2
0
        public ActionResult Upload(CreateGameViewModel viewModel)
        {
            this.storageService.TempStoragePath = Server.MapPath("~/Temp");

            //try
            //{
            if (viewModel.File.ContentLength > 0)
            {
                string filename = Path.GetFileName(viewModel.File.FileName);
                string path     = Path.Combine(Server.MapPath("~/Temp"), filename);
                viewModel.File.SaveAs(path);
                this.storageService.SaveFile(filename, path);
            }

            this.gameService.Create(viewModel.Name, viewModel.Description, User.Identity.Name);

            ViewBag.Message = "File Uploaded Successfully!!";

            return(View());
            //}
            //catch
            //{
            //    ViewBag.Message = "File upload failed!!";
            //    return View();
            //}
        }
Ejemplo n.º 3
0
        public ActionResult Create(CreateGameViewModel viewModel)
        {
            var game = new Game
            {
                CreatedDate = DateTime.Now,
                Course      = courseRepository.Get(viewModel.SelectedCourseId)
            };

            game.AddPlayer(userRepository.GetByUserName(User.Identity.Name));
            foreach (var selectedOtherUser in viewModel.SelectedOtherUserNames)
            {
                game.AddPlayer(userRepository.GetByUserName(selectedOtherUser));
            }
            game.CreateRounds();

            if (ModelState.IsValid)
            {
                gameRepository.Create(game);
                gameRepository.Save();

                return(RedirectToAction("Continue", new { id = game.Id }));
            }

            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public void Creating_Game_Assigns_Players_Correctly()
        {
            // arrange
            playerRepository.Setup(r => r.GetCpuPlayer()).Returns(cpuPlayer);
            var vm = new CreateGameViewModel
                         {
                             Description = "description",
                             SovietUnion = GameViewModel.PlayerCpu.Cpu,
                             Germany = GameViewModel.PlayerCpu.Open,
                             UnitedKingdom = GameViewModel.PlayerCpu.Self,
                             Japan = GameViewModel.PlayerCpu.Cpu,
                             UnitedStates = GameViewModel.PlayerCpu.Self
                         };

            // act
            controller.Create(vm);

            // assert
            // created with correct player settings:
            gameFactory.Verify(f => f.Create(currentPlayer, "description",
                                             cpuPlayer,
                                             null,
                                             currentPlayer,
                                             cpuPlayer,
                                             currentPlayer
                                        ));
        }
Ejemplo n.º 5
0
        public ActionResult EditGame(CreateGameViewModel gameViewModel) // TODO : game editing
        {
            var gameFromDb = _gameManager.GetGameByKey(gameViewModel.Key);

            Mapper.Map(gameViewModel, gameFromDb);

            gameFromDb.Genres.RemoveAll(x => gameViewModel.SelectedGenres.All(f => f != x.Id));
            gameFromDb.Publishers.RemoveAll(x => gameViewModel.SelectedPublishers.All(f => f != x.Id));
            gameFromDb.Platforms.RemoveAll(x => gameViewModel.SelectedPlatforms.All(f => f != x.Id));

            if (gameViewModel.SelectedGenres != null)
            {
                var newGenresIds = gameViewModel.SelectedGenres.Except(gameFromDb.Genres.Select(g => g.Id));
                var newGenres    = _genreManager.Find(f => newGenresIds.Any(g => g == f.Id));
                gameFromDb.Genres.AddRange(newGenres);
            }

            if (gameViewModel.SelectedPlatforms != null)
            {
                var newPlatformsIds = gameViewModel.SelectedPlatforms.Except(gameFromDb.Platforms.Select(g => g.Id));
                var newPlatforms    = _platformManager.Find(f => newPlatformsIds.Any(g => g == f.Id));
                gameFromDb.Platforms.AddRange(newPlatforms);
            }

            if (gameViewModel.SelectedPublishers != null)
            {
                var newPublishersIds = gameViewModel.SelectedPublishers.Except(gameFromDb.Publishers.Select(g => g.Id));
                var newPublishers    = _publisherManager.Find(f => newPublishersIds.Any(g => g == f.Id));
                gameFromDb.Publishers.AddRange(newPublishers);
            }

            _gameManager.EditGame(gameFromDb);

            return(RedirectToAction("GetAllGames"));
        }
Ejemplo n.º 6
0
        //public async Task<IActionResult> Create([Bind("Id,Name,Price,Promotion,Description,PG")] Game game)
        public async Task <IActionResult> Create(CreateGameViewModel vm)
        {
            //Category category = _context.Categories.Find(vm.IdCategory);
            //Studio studio = _context.Studios.Find(vm.IdStudio);

            var game = new Game
            {
                Name        = vm.Game.Name,
                CategoryId  = vm.Game.CategoryId,
                StudioId    = vm.Game.StudioId,
                Price       = vm.Game.Price,
                Promotion   = vm.Game.Promotion,
                Description = vm.Game.Description,
                PG          = vm.Game.PG,
            };

            //if (ModelState.IsValid)
            //{
            _context.Add(game);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
            //}
            //return View(vm);
        }
Ejemplo n.º 7
0
        public ActionResult Create(CreateGameViewModel model)
        {
            Game game = Mapper.Map <CreateGameViewModel, Game>(model);

            _gameService.CreateGame(game);
            _gameService.SaveGame();
            return(RedirectToAction("Details", "FilterItem"));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> AddGame()
        {
            CreateGameViewModel createGame = new CreateGameViewModel
            {
                GameCriterias = await GetGameCriterias()
            };

            return(View(createGame));
        }
Ejemplo n.º 9
0
        public ActionResult CreateGame()
        {
            CreateGameViewModel createGameViewModel = new CreateGameViewModel()
            {
                Sports = dbContext.Sports.ToList()
            };

            return(View(createGameViewModel));
        }
Ejemplo n.º 10
0
        public AddMatchPage()
        {
            InitializeComponent();
            gameData.Game        = new Game();
            gameData.HomeTeam    = new Team();
            gameData.VisitorTeam = new Team();

            BindingContext = new CreateGameViewModel(Navigation, gameData);
        }
Ejemplo n.º 11
0
        public async Task <string> AddGame(CreateGameViewModel model, GoUser user)
        {
            byte[] imageLevel1 = ImageAsBytes(model.Level1.Image);
            byte[] imageLevel2 = ImageAsBytes(model.Level2.Image);
            byte[] imageLevel3 = ImageAsBytes(model.Level3.Image);

            var game = new Game
            {
                Name        = model.Name,
                Description = model.Description,
                Image       = imageLevel3,
                CreatorId   = user.Id
            };

            await this.gamesRepository.AddAsync(game);

            await this.gamesRepository.SaveChangesAsync();

            var level1 = new Level
            {
                Image        = imageLevel1,
                Description  = model.Level1.Description,
                NumberInGame = model.Level1.NumberInGame,
                GameId       = game.Id,
                Game         = game,
                Points       = model.Level1.Points
            };
            var level2 = new Level
            {
                Image        = imageLevel2,
                Description  = model.Level2.Description,
                NumberInGame = model.Level2.NumberInGame,
                GameId       = game.Id,
                Game         = game,
                Points       = model.Level2.Points
            };
            var level3 = new Level
            {
                Image        = imageLevel3,
                Description  = model.Level3.Description,
                NumberInGame = model.Level3.NumberInGame,
                GameId       = game.Id,
                Game         = game,
                Points       = model.Level3.Points
            };

            await this.levelsRepository.AddAsync(level1);

            await this.levelsRepository.AddAsync(level2);

            await this.levelsRepository.AddAsync(level3);

            await this.levelsRepository.SaveChangesAsync();

            return(game.Id);
        }
Ejemplo n.º 12
0
        public ViewResult Create()
        {
            ViewBag.Title = "Создание игры";
            var model = new CreateGameViewModel(categoryRepository.Category)
            {
                Game = new Game(),
            };

            return(View("Edit", model));
        }
Ejemplo n.º 13
0
        private void SetMultiSelectListsForCreateGameViewModel(CreateGameViewModel model)
        {
            IEnumerable <GenreDto>        genres        = _genreService.GetAllGenres();
            IEnumerable <PlatformTypeDto> platformTypes = _platformTypeService.GetAllPlatformTypes();
            IEnumerable <PublisherDto>    publishers    = _publisherService.GetAllPublishers();

            model.Genres        = new MultiSelectList(genres, "Id", "Name");
            model.PlatformTypes = new MultiSelectList(platformTypes, "Id", "Type");
            model.Publishers    = new MultiSelectList(publishers, "Id", "CompanyName");
        }
Ejemplo n.º 14
0
        // GET: Game/Create
        public IActionResult Create()
        {
            var viewModel = new CreateGameViewModel
            {
                Genres     = _context.Genres,
                Developers = _context.Developers
            };

            return(View(viewModel));
        }
Ejemplo n.º 15
0
        public ActionResult CreateWithCustomImage(CreateGameViewModel model, HttpPostedFileBase imageFile)
        {
            var game = mapper.Map <CreateGameViewModel, Game>(model);

            game.Image = ImageHelper.SaveImage(Server, imageFile);

            gameService.CreateGame(game);

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Create(CreateGameViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            await this.gamesService.GameCreateAsync(input);

            return(this.RedirectToAction(nameof(this.Index)));
        }
Ejemplo n.º 17
0
        public ActionResult Create()
        {
            var viewModel = new CreateGameViewModel
            {
                Courses    = courseRepository.GetAll(),
                OtherUsers = userRepository.GetAll()
                             .Where(x => x.UserName != User.Identity.Name).ToList()
            };

            return(View(viewModel));
        }
Ejemplo n.º 18
0
        public ActionResult CreateNewGame()
        {
            using (var client = ServiceHelper.GetServiceClientWithCredentials(loginViewModel.Username, loginViewModel.Password))
            {
                List <QuestionSet> questionSet = new List <QuestionSet>();
                var qs = client.RetrieveAllQuestionSets().ToList();
                CreateGameViewModel viewModel = new CreateGameViewModel();
                viewModel.QuestionSets = qs;

                return(View(viewModel));
            }
        }
Ejemplo n.º 19
0
        public ActionResult NewGame(CreateGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                SetMultiSelectListsForCreateGameViewModel(model);
                return(View(model));
            }

            _gameService.Create(model.ToCreatingDto());

            return(RedirectToAction("GetAll"));
        }
Ejemplo n.º 20
0
        public ViewResult NewGame()
        {
            var model = new CreateGameViewModel
            {
                GenresIds        = new List <int>(),
                PlatformTypesIds = new List <int>(),
            };

            SetMultiSelectListsForCreateGameViewModel(model);

            return(View(model));
        }
Ejemplo n.º 21
0
        public HttpResponseMessage Put(string key, [FromBody] CreateGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var gameDto = Mapper.Map <GameDTO>(model);

            _gameService.EditEntity(gameDto);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Create(CreateGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View());
            }

            var user = await userManager.GetUserAsync(HttpContext.User);

            string gameId = await this.gamesService.AddGame(model, user);

            return(Redirect($"/Games/All"));
        }
Ejemplo n.º 23
0
        public ActionResult Create(CreateGameViewModel model)
        {
            if (ModelState.IsValid)
            {
                var game = _mapper.Map <Game>(model);
                _unitOfWork.Games.Insert(game);
                _unitOfWork.Save();

                return(RedirectToAction("All"));
            }

            return(View());
        }
Ejemplo n.º 24
0
        // GET: Games/Create
        public IActionResult Create()
        {
            var gvm = new CreateGameViewModel();

            gvm.Users =
                (from user in _context.Users
                 select new SelectListItem {
                Value = user.Id.ToString(), Text = user.DisplayName
            })
                .ToList();

            return(View(gvm));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> CreateGame(CreateGameViewModel model)
        {
            var game = new Game
            {
                ID         = _repo.GetNewId(),
                Name       = model.Name,
                AdminToken = _repo.GetNewId()
            };

            await _repo.UpdateGame(game);

            return(RedirectToAction("Index", "Admin", new { game.ID, game.AdminToken }));
        }
Ejemplo n.º 26
0
        public async Task <ActionResult> Create(CreateGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var game = Mapper.Map <CreateGameViewModel, Game>(model);

            gameService.CreateGame(game);
            await gameService.SaveGameAsync();

            return(View());
        }
Ejemplo n.º 27
0
        public ActionResult Create(CreateGameViewModel model)
        {
            _context.Games.Add(new Games {
                Name        = model.Name,
                DateRelease = model.DateRelease,
                URL_Image   = model.URL_Image,
                Developer   = model.Developer,
                Price       = model.Price,
                Description = model.Description
            });
            _context.SaveChanges();

            return(RedirectToAction("Index", "Game"));
        }
Ejemplo n.º 28
0
        public async Task <ActionResult> AddGame(GameViewModel game)
        {
            if (ModelState.IsValid)
            {
                var res = await _gameService.CreateGameAsync(_mapper.Map <GameViewModel, GameDTO>(game));
            }
            CreateGameViewModel createGame = new CreateGameViewModel
            {
                GameCriterias = await GetGameCriterias(),
                Game          = game
            };

            return(View(createGame));
        }
Ejemplo n.º 29
0
        public ActionResult Edit(int gameId = 0)
        {
            ViewBag.Title = "Редактирование игры";
            CreateGameViewModel model = new CreateGameViewModel(categoryRepository.Category, gameId)
            {
                Game = gameRepository.Games.FirstOrDefault(g => g.GameId == gameId)
            };

            if (gameId == 0 || model.Game == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Ejemplo n.º 30
0
        public ActionResult CreateGame()
        {
            var gameViewModel = new CreateGameViewModel();

            var genresFromDb     = _genreManager.GetAllGenres().ToList();
            var platformsFromDb  = _platformManager.GetAllPlatforms().ToList();
            var publishersFromDb = _publisherManager.GetAllPublishers().ToList();

            gameViewModel.AllGenres     = new MultiSelectList(genresFromDb.OrderBy(i => i.Category), "Id", "Name", "Category");
            gameViewModel.AllPlatforms  = new MultiSelectList(platformsFromDb.OrderBy(i => i.Type), "Id", "Type");
            gameViewModel.AllPublishers = new MultiSelectList(publishersFromDb.OrderBy(i => i.CompanyName), "Id", "CompanyName");

            return(View("CreateGame", gameViewModel));
        }
Ejemplo n.º 31
0
        public ActionResult CreateNewGame(CreateGameViewModel viewModel)
        {
            using (var client = ServiceHelper.GetServiceClientWithCredentials(loginViewModel.Username, loginViewModel.Password))
            {
                Game ourGame = new Game();
                if (viewModel != null)
                {
                    ourGame             = viewModel.Game;
                    ourGame.QuestionSet = client.RetrieveQuestionSet(viewModel.SelectedQuestionSetID);
                    client.CreateGame(ourGame);
                }

                return(RedirectToAction("GetActiveGames", "JoinGame"));
            }
        }
Ejemplo n.º 32
0
 public ActionResult Create(CreateGameViewModel game)
 {
     game.CurrentPlayer = currentPlayer;
     game.CpuPlayer = playerRepository.GetCpuPlayer();
     Game g = gameFactory.Create(game.CurrentPlayer,
                                 game.Description,
                                 game.GetSovietPlayer(),
                                 game.GetGermanPlayer(),
                                 game.GetBritishPlayer(),
                                 game.GetJapanesePlayer(),
                                 game.GetAmericanPlayer());
     gameRepository.Save(g);
     return ToAllGamesList();
 }