Пример #1
0
        public ActionResult Save(GameModel game)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel(game)
                {
                    Categories = _context.Categories.ToList()
                };
                return(View("GameForm", viewModel));
            }

            if (game.Id == 0)
            {
                game.DateAdded = DateTime.Now;
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(m => m.Id == game.Id);
                gameInDb.Name          = game.Name;
                gameInDb.CategoryId    = game.CategoryId;
                gameInDb.NumberInStock = game.NumberInStock;
                gameInDb.ReleaseDate   = game.ReleaseDate;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Games"));
        }
Пример #2
0
        public ActionResult Save(Game game)
        {
            game.Name = BuildGameName(game);
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel
                {
                    Teams = _context.Teams.OrderBy(x => x.Name).ToList(),
                    Weeks = _context.Weeks.OrderByDescending(x => x.Id).ToList(),
                    Game  = game
                };
                return(View("GameForm", viewModel));
            }

            if (game.Id == 0)
            {
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(g => g.Id == game.Id);

                gameInDb.Name           = game.Name;
                gameInDb.HomeTeamId     = game.HomeTeamId;
                gameInDb.VisitTeamId    = game.VisitTeamId;
                gameInDb.HomeTeamScore  = game.HomeTeamScore;
                gameInDb.VisitTeamScore = game.VisitTeamScore;
                gameInDb.Spread         = game.Spread;
                gameInDb.Active         = game.Active;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Game"));
        }
Пример #3
0
        public ActionResult Save(Game game)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel
                {
                    Game   = game,
                    Genres = _context.Genres.ToList()
                };
                return(View("GameForm", viewModel));
            }
            if (game.Id == 0)
            {
                game.NumberAvailable = game.NumberInStock;
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(g => g.Id == game.Id);
                gameInDb.Name            = game.Name;
                gameInDb.GenreId         = game.GenreId;
                gameInDb.NumberInStock   = game.NumberInStock;
                gameInDb.Price           = game.Price;
                gameInDb.NumberAvailable = game.NumberAvailable;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Games"));
        }
        public ActionResult Save(Game game)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel
                {
                    Game       = game,
                    Categories = _context.Categories.ToList()
                };


                return(View("GameForm", viewModel));
            }


            if (game.GameID == 0)
            {
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(c => c.GameID == game.GameID);

                gameInDb.Name              = game.Name;
                gameInDb.GameFor           = game.GameFor;
                gameInDb.GamePrice         = game.GamePrice;
                gameInDb.GameYearPublished = game.GameYearPublished;
                gameInDb.CategoryID        = game.CategoryID;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Games"));
        }
Пример #5
0
        public ActionResult Save(Game Game)
        {
            ModelState.Remove("Game.Id");
            ModelState.Remove("Game.CategoryId");
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel {
                    Game       = Game,
                    Categories = _dbContext.Category.ToList()
                };

                return(View("FormGame", viewModel));
            }

            if (Game.Id == 0)
            {
                _dbContext.Games.Add(Game);
            }
            else
            {
                Game dbGameContext = _dbContext.Games.Single(m => m.Id == Game.Id);

                dbGameContext.CategoryId = Game.CategoryId;
                dbGameContext.Date       = Game.Date;
                dbGameContext.Descricao  = Game.Descricao;
                dbGameContext.ImageUrl   = Game.ImageUrl;
                dbGameContext.Name       = Game.Name;
            }

            _dbContext.SaveChanges();

            return(RedirectToAction("Game"));
        }
Пример #6
0
        public ActionResult Save(GameFormViewModel newGame)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel
                {
                    GenreTypeId = newGame.GenreTypeId,
                    Name        = newGame.Name,
                    ReleaseDate = newGame.ReleaseDate,
                    Id          = newGame.Id ?? 0,
                    GenreTypes  = this.referenceService.GetGenreTypes()
                };

                return(View("GameForm", viewModel));
            }

            var gameModel = this.mapper.Map <GameFormViewModel, GameModel>(newGame);

            if (gameModel.Id == 0)
            {
                this.gameService.AddGame(gameModel);
            }
            else
            {
                this.gameService.UpdateGame(gameModel);
            }

            return(RedirectToAction("GetGames", "Game"));
        }
        public ActionResult Create()
        {
            var viewModel = new GameFormViewModel();

            var genres = db.Genres.Select(g => new
            {
                GenreId = g.Id,
                GenreName = g.Name
            }).ToList();

            var platforms = db.Platforms.Select(p => new
            {
                PlatformId = p.Id,
                PlatformName = p.Name
            }).ToList();

            viewModel.Id = -1;

            viewModel.Platforms = new MultiSelectList(platforms, "PlatformId", "PlatformName");
            //viewModel.SelectedPlatforms = new[] {Platform.PC,Platform.Switch,Platform.Android};
            viewModel.Genres = new MultiSelectList(genres, "GenreId", "GenreName");
            //viewModel.SelectedGenres = new[] {1, 3, 4};

            return View(viewModel);
        }
Пример #8
0
        public GameFormViewModel GetFullGameForm(int?id)
        {
            List <int> selectedLanguagesId = null;
            List <int> selectedTagsId      = null;
            var        game = _gameService.Find(id);

            if (game != null)
            {
                selectedLanguagesId = game.Languages.Select(l => l.Id).ToList();
                selectedTagsId      = game.Tags.Select(l => l.Id).ToList();
            }

            var gameViewModel = new GameFormViewModel
            {
                Platforms           = _platformService.GetAll(),
                Statuses            = _statusService.GetAll(),
                Genres              = _genreService.GetAll(),
                Series              = _seriesService.GetAll(),
                Publishers          = _companyService.GetAll(),
                Developers          = _companyService.GetAll(),
                Languages           = _languageService.GetAll(),
                Tags                = _tagService.GetAll(),
                Game                = game,
                selectedLanguagesId = selectedLanguagesId,
                selectedTagsId      = selectedTagsId,
                ImageTypes          = _imageTypeService.GetByType(ImageTypes.Game),
                FilterLetters       = _steamApi.GetFilterLetters()
            };

            return(gameViewModel);
        }
        public ActionResult Save(Game game)
        {
            // var movieInDb = _context.Movies.SingleOrDefault(m => m.Id == id);
            if (!ModelState.IsValid)
            {
                var viewmodel = new GameFormViewModel(game);

                return(View("GameForm", viewmodel));
            }
            if (game.Id == 0)
            {
                _context.Games.Add(game);
            }

            else
            {
                var gameINDb = _context.Games.Single(c => c.Id == game.Id);
                gameINDb.Name        = game.Name;
                gameINDb.Description = game.Description;
                gameINDb.Price       = game.Price;
                gameINDb.Category    = game.Category;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Games"));
        }
        public ActionResult Save(Game game)
        {
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors })
                         .ToArray();

            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel()
                {
                    Game   = game,
                    Genres = _context.Genres.ToList()
                };
                return(View("GameForm", viewModel));
            }

            if (game.Id == 0)
            {
                game.DateAdded = DateTime.Now.ToString("yyyy-MM-dd");
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(g => g.Id == game.Id);
                gameInDb.Name          = game.Name;
                gameInDb.ReleaseDate   = game.ReleaseDate;
                gameInDb.NumberInStock = game.NumberInStock;
                gameInDb.GenreId       = game.GenreId;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Games"));
        }
        public ActionResult Save(Game game)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel(game)
                {
                    Categories = _context.Categories.ToList()
                };

                return(View("GameForm", viewModel));
            }

            if (game.Id == 0)
            {
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(c => c.Id == game.Id);
                gameInDb.Name     = game.Name;
                gameInDb.Category = game.Category;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Game"));
        }
Пример #12
0
        public ActionResult Save(Game game)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel
                {
                    Game      = game,
                    GameTypes = _context.GameTypes.ToList()
                };

                return(View("GameForm", viewModel));
            }

            if (game.Id == 0)
            {
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(c => c.Id == game.Id);

                gameInDb.Name          = game.Name;
                gameInDb.ReleaseDate   = game.ReleaseDate;
                gameInDb.GameTypeId    = game.GameTypeId;
                gameInDb.NumberInStock = game.NumberInStock;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Games"));
        }
Пример #13
0
        public ActionResult Save(Game game)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel(game)
                {
                    Genres = _context.Genres.ToList()
                };

                return(View("GameForm", viewModel));
            }



            if (game.Id == 0)
            {
                game.DateAdded = DateTime.Now;
                _context.Games.Add(game);
            }
            else
            {
                var gameInDb = _context.Games.Single(g => g.Id == game.Id);
                gameInDb.Name          = game.Name;
                gameInDb.GenreId       = game.GenreId;
                gameInDb.NumberInStock = game.NumberInStock;
                gameInDb.ReleaseDate   = game.ReleaseDate;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Games")); //send user back to the index page for games after editing
        }
Пример #14
0
        public ActionResult Save(Game games)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel(games)
                {
                    Genres = _context.Genres.ToList()
                };

                return(View("GameForm", viewModel));
            }
            if (games.Id == 0)
            {
                _context.Games.Add(games);
            }
            else
            {
                var gameInDb = _context.Games.Single(g => g.Id == games.Id);

                gameInDb.Name     = games.Name;
                gameInDb.Price    = games.Price;
                gameInDb.GenreId  = games.GenreId;
                gameInDb.Quantity = games.Quantity;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Games"));
        }
Пример #15
0
        public ActionResult Save(Game game)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new GameFormViewModel
                {
                    Game     = game,
                    Genres   = _context.Genres.ToList(),
                    Consoles = _context.Consoles.ToList()
                };
                return(View("GameForm", viewModel));
            }

            if (game.Id == 0)
            {
                game.DateAdded = DateTime.Now;
                _context.Games.Add(game);
            }
            else
            {
                var GameInDb = _context.Games.Single(c => c.Id == game.Id);

                GameInDb.Name        = game.Name;
                GameInDb.ReleaseDate = game.ReleaseDate;
                GameInDb.GenreId     = game.GenreId;
                GameInDb.ConsoleId   = game.ConsoleId;
                GameInDb.Price       = game.Price;
                GameInDb.Stock       = game.Stock;
                GameInDb.Link        = game.Link;
            }
            _context.SaveChanges();


            return(RedirectToAction("index", "Games"));
        }
Пример #16
0
        public ActionResult Edit(int id)
        {
            GameFormViewModel viewModel = GameFormViewModel.CreateGameFormViewModel();

            viewModel.Game = gameRepository.Get(id);
            this.SetBreadcrumbText(viewModel.Game.Name);
            return(View(viewModel));
        }
Пример #17
0
        public ActionResult New()
        {
            var GameViewModel = new GameFormViewModel()
            {
                Categories = _dbContext.Category.ToList()
            };

            ViewBag.CategoryId = new SelectList(_dbContext.Category, "Id", "CategoryName");
            return(View("FormGame", GameViewModel));
        }
Пример #18
0
        public ActionResult New()
        {
            var genres       = referenceService.GetGenreTypes();
            var newGameModel = new GameFormViewModel
            {
                GenreTypes = genres
            };

            return(View("GameForm", newGameModel));
        }
        public ActionResult Create()
        {
            var viewModel = new GameFormViewModel
            {
                Categories = context.Categories.ToList(),
                Heading    = "Add a game"
            };

            return(View("GameForm", viewModel));
        }
Пример #20
0
        public ActionResult New()
        {
            var genres    = _context.Genres.ToList();
            var viewModel = new GameFormViewModel
            {
                Genres = genres
            };

            return(View("GameForm", viewModel));
        }
Пример #21
0
        public ActionResult New()
        {
            var tickets = _context.Tickets.ToList().OrderBy(m => m.Section);
            List <SelectListItem> listSelectListItems = new List <SelectListItem>();

            var categories = _context.Ref_Category.ToList();
            List <SelectListGroup> groups = new List <SelectListGroup>();

            foreach (Ref_Category ct in categories)
            {
                var group = new SelectListGroup()
                {
                    Name = ct.Name.Replace(" ", "&nbsp")
                };
                groups.Add(group);
            }

            foreach (Ticket t in tickets)
            {
                var grp = new SelectListGroup();
                switch (t.CategoryId)
                {
                case 1:
                    grp = groups.ElementAt(0);
                    break;

                case 2:
                    grp = groups.ElementAt(1);
                    break;

                case 3:
                    grp = groups.ElementAt(2);
                    break;
                }
                SelectListItem selectList = new SelectListItem()
                {
                    Text  = t.getPosition(),
                    Value = t.Id.ToString(),
                    Group = grp
                };
                listSelectListItems.Add(selectList);
            }

            var competitions = _context.Ref_Competition.ToList();

            var viewModel = new GameFormViewModel
            {
                Competitions = competitions,
                Tickets      = listSelectListItems,
                Groups       = groups
            };

            return(View("Form", viewModel));
        }
        public ViewResult New()
        {
            var categories = _context.Categories.ToList();

            var viewModel = new GameFormViewModel()
            {
                Categories = categories
            };

            return(View("GameForm", viewModel));
        }
Пример #23
0
        public ActionResult New()
        {
            var viewModel = new GameFormViewModel
            {
                Teams = _context.Teams.OrderBy(x => x.Name).ToList(),
                Weeks = _context.Weeks.OrderByDescending(x => x.Id).ToList(),
                Game  = new Game()
            };

            return(View("GameForm", viewModel));
        }
Пример #24
0
        public ActionResult New()
        {
            var Categories = _context.Categories.ToList();
            var ViewModel  = new GameFormViewModel
            {
                Game       = new Game(),
                Categories = Categories
            };

            return(View("GameForm", ViewModel));
        }
Пример #25
0
        public ActionResult Add()
        {
            var vm = new GameFormViewModel();

            vm.FormName = "Add";

            vm.Game = new Game();


            return(PartialView("GameForm", vm));
        }
Пример #26
0
 private static Game ViewModelToDomain(GameFormViewModel gameFormViewModel)
 {
     return(new Game
     {
         Developer = gameFormViewModel.Developer,
         GameName = gameFormViewModel.GameName,
         Platform = gameFormViewModel.Platform,
         Publisher = gameFormViewModel.Publisher,
         ReleaseYear = gameFormViewModel.ReleaseYear
     });
 }
Пример #27
0
        public ActionResult New()
        {
            var gameTypes = _context.GameTypes.ToList();
            var viewModel = new GameFormViewModel
            {
                Game      = new Game(),
                GameTypes = gameTypes
            };

            return(View("GameForm", viewModel));
        }
        public ActionResult Edit(int id)
        {
            var game = _context.Games.SingleOrDefault(m => m.Id == id);

            if (game == null)
            {
                return(HttpNotFound());
            }
            var viewmodel = new GameFormViewModel(game);

            return(View("GameForm", viewmodel));
        }
Пример #29
0
        public ActionResult Edit(int id)
        {
            var genres = _context.Genres.ToList();
            var game   = _context.Games.SingleOrDefault(g => g.Id == id);

            var viewModel = new GameFormViewModel(game)
            {
                Genres = genres
            };

            return(View("GameForm", viewModel));
        }
Пример #30
0
        public ActionResult New()
        {
            var genres    = _context.GameGenres.ToList();
            var platforms = _context.GamePlatforms.ToList();

            var viewModel = new GameFormViewModel
            {
                Game      = new Game(),
                Genres    = genres,
                Platforms = platforms
            };

            return(View("GameForm", viewModel));
        }
Пример #31
0
            /// <summary>
            /// Creation method for creating the view model. Services may be passed to the creation 
            /// method to instantiate items such as lists for drop down boxes.
            /// </summary>
            public static GameFormViewModel CreateGameFormViewModel()
            {
                GameFormViewModel viewModel = new GameFormViewModel();

                return viewModel;
            }