コード例 #1
0
ファイル: GameController.cs プロジェクト: lorfol/GameStore
        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"));
        }