示例#1
0
        public async Task <IActionResult> UpdateAsync(ModifyGameViewModel modifyGameViewModel)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = await _gameViewModelFactory.CreateAsync(modifyGameViewModel);

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

            var dto = _mapper.Map <ModifyGameDto>(modifyGameViewModel);

            try
            {
                await _gameService.UpdateAsync(dto);
            }
            catch (ValidationException <GameRoot> e)
            {
                const string prefix = nameof(ModifyGameViewModel);
                ModelState.AddModelError($"{prefix}.{e.Key}", e.Message);

                var viewModel = await _gameViewModelFactory.CreateAsync(modifyGameViewModel);

                _logger.LogWarning(e.Message);

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

            _logger.LogDebug($"The game with id {modifyGameViewModel.Id} was updated in database");

            return(RedirectToAction(nameof(GetAllAsync)));
        }
示例#2
0
        private static ModifyGameViewModel CreateGameViewModel()
        {
            var testViewModel = new ModifyGameViewModel
            {
                Name        = "Name",
                Description = "Description"
            };

            return(testViewModel);
        }
示例#3
0
        public async Task <IActionResult> UpdateAsync(ModifyGameViewModel modifyGameViewModel)
        {
            var dto = _mapper.Map <ModifyGameDto>(modifyGameViewModel);

            try
            {
                await _gameService.UpdateAsync(dto);
            }
            catch (ValidationException <GameRoot> e)
            {
                const string prefix = nameof(ModifyGameViewModel);
                ModelState.AddModelError($"{prefix}.{e.Key}", e.Message);

                _logger.LogWarning(e.Message);

                return(BadRequest(ModelState));
            }

            _logger.LogDebug($"The game with id {modifyGameViewModel.Id} was updated in database");

            return(NoContent());
        }
示例#4
0
        public async Task <IActionResult> CreateAsync(ModifyGameViewModel modifyGameViewModel)
        {
            modifyGameViewModel.Id = Guid.NewGuid().ToString();
            var dto = _mapper.Map <ModifyGameDto>(modifyGameViewModel);

            try
            {
                await _gameService.CreateAsync(dto);
            }
            catch (ValidationException <GameRoot> e)
            {
                const string prefix = nameof(ModifyGameViewModel);
                ModelState.AddModelError($"{prefix}.{e.Key}", e.Message);

                _logger.LogWarning(e.Message);

                return(BadRequest(ModelState));
            }

            _logger.LogDebug($"A new game with name: {modifyGameViewModel.Name} was added to database");

            return(CreatedAtAction(nameof(GetByIdAsync), new{ id = modifyGameViewModel.Id }, modifyGameViewModel));
        }
示例#5
0
        private static ModifyGameViewModel GetModifyGameViewModel()
        {
            var viewModel = new ModifyGameViewModel();

            return(viewModel);
        }