Ejemplo n.º 1
0
        public IActionResult Update(GameViewModel gameViewModel)
        {
            if (!ModelState.IsValid)
            {
                gameViewModel.Authors = _authorRepository.GetAll();
                return(View(gameViewModel));
            }

            var game = gameViewModel.Game;

            var game2 = _favoriteRepository.GetAllChangesForGame(game.GameId);

            if (game2.Count() == 0)
            {
                _favoriteRepository.Create(new Favorites
                {
                    NewGame = new NamePrice
                    {
                        Name   = gameViewModel.Game.Name,
                        Price  = gameViewModel.Game.Price,
                        GameID = gameViewModel.Game.GameId
                    },

                    OldGame = new NamePrice {
                        Name = "UNregistered", Price = 0
                    },
                    Date = DateTime.Now
                });
            }
            else
            {
                var game1 = game2.First();

                var fav = new Favorites
                {
                    OldGame = new NamePrice
                    {
                        Name   = game1.NewGame.Name,
                        Price  = game1.NewGame.Price,
                        GameID = game1.NewGame.GameID
                    },
                    NewGame = new NamePrice
                    {
                        Name   = gameViewModel.Game.Name,
                        Price  = gameViewModel.Game.Price,
                        GameID = gameViewModel.Game.GameId
                    },
                    Date = DateTime.Now
                };

                _favoriteRepository.Create(fav);
            }

            _gameRepository.Update(gameViewModel.Game);

            return(RedirectToAction("List"));
        }
Ejemplo n.º 2
0
        public IActionResult AddToFavorite(int id)
        {
            var game = _gameRepository.getById(id);

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("List"));
            }

            _gameHistory.List = _favoriteRepository.GetAllChangesForGame(id).ToList();



            return(RedirectToAction("List"));
        }