Exemple #1
0
        public async Task <IActionResult> Edit(int id, string param)
        {
            var game = gameRepository.Get(id);

            if (game == null)
            {
                throw new InvalidOperationException("Entity does not exist.");
            }

            var model = new BoardGameCreateUpdateViewModel();

            if (await TryUpdateModelAsync(model))
            {
                game.MaxPlayersNumber = model.MaxPlayersNumber;
                game.MinPlayerAge     = model.MinPlayerAge;
                game.MinPlayersNumber = model.MinPlayersNumber;
                game.Name             = model.Name;

                gameRepository.CreateOrUpdate(game);
            }

            if (ModelState.ErrorCount > 0)
            {
                return(View());
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public IActionResult Edit(int id)
        {
            var game = gameRepository.Get(id);

            if (game == null)
            {
                throw new InvalidOperationException("Entity does not exist.");
            }

            var model = new BoardGameCreateUpdateViewModel()
            {
                Id               = game.Id,
                MinPlayerAge     = game.MinPlayerAge,
                MaxPlayersNumber = game.MaxPlayersNumber,
                MinPlayersNumber = game.MinPlayersNumber,
                Name             = game.Name
            };

            return(View(model));
        }
Exemple #3
0
        public async Task <IActionResult> Create(string param)
        {
            var model = new BoardGameCreateUpdateViewModel();

            if (await TryUpdateModelAsync(model))
            {
                var newRecord = new BoardGameRecord()
                {
                    MinPlayerAge     = model.MinPlayerAge,
                    MaxPlayersNumber = model.MaxPlayersNumber,
                    MinPlayersNumber = model.MinPlayersNumber,
                    Name             = model.Name
                };

                gameRepository.CreateOrUpdate(newRecord);
            }

            if (ModelState.ErrorCount > 0)
            {
                return(View());
            }

            return(RedirectToAction("Index"));
        }