Beispiel #1
0
        public ActionResult UpdateGame(UpdateGameViewModel model)
        {
            IDictionary <string, string> languagesNames        = new Dictionary <string, string>();
            IDictionary <string, string> languagesDescriptions = new Dictionary <string, string>();

            languagesNames.Add("ru", model.Name);
            languagesDescriptions.Add("ru", model.Description);

            if (model.IsContainEnglishTranslation)
            {
                languagesNames.Add("en", model.EnglishName);
                languagesDescriptions.Add("en", model.EnglishDescription);
            }

            _gameService.Edit(
                model.GameId,
                languagesNames,
                languagesDescriptions,
                model.Price,
                model.UnitsInStock,
                model.Discounted,
                model.PlatformTypeIds,
                model.PublisherIds,
                model.GenreIds);

            return(RedirectToAction("GetAll"));
        }
Beispiel #2
0
        public static EditingGameDto ToEditingDto(this UpdateGameViewModel model)
        {
            var languagesNames        = new Dictionary <string, string>();
            var languagesDescriptions = new Dictionary <string, string>();

            languagesNames.Add("ru", model.Name);
            languagesDescriptions.Add("ru", model.Description);

            if (model.IsContainEnglishTranslation)
            {
                languagesNames.Add("en", model.EnglishName);
                languagesDescriptions.Add("en", model.EnglishDescription);
            }

            return(new EditingGameDto
            {
                GameId = model.GameId,
                LanguagesNames = languagesNames,
                LanguagesDescriptions = languagesDescriptions,
                Price = model.Price,
                UnitsInStock = model.UnitsInStock,
                Discounted = model.Discounted,
                PlatformTypeIds = model.PlatformTypeIds,
                PublisherIds = model.PublisherIds,
                GenreIds = model.GenreIds
            });
        }
        public ActionResult UpdateGame(UpdateGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Update", model));
            }

            _gameService.Edit(model.ToEditingDto());

            return(RedirectToAction("GetAll"));
        }
Beispiel #4
0
        public IActionResult Game(Guid id, UpdateGameViewModel updateGameViewModel)
        {
            var game = _context.GameEntityModels.First(g => g.Id == id);
            var c    = _context.CommissionerEnties.First(g => g.Id == updateGameViewModel.Commissioner.ToString());
            var r1   = _context.RefereeEntities.First(g => g.Id == updateGameViewModel.Referee1.ToString());
            var r2   = _context.RefereeEntities.First(g => g.Id == updateGameViewModel.Referee2.ToString());

            game.Commissioner = c;
            game.Referee1     = r1;
            game.Referee2     = r2;
            _context.Update(game);
            _context.SaveChanges();
            return(LocalRedirect(Url.Action("", "Home")));
        }
        public void ShouldMap_GameDto_To_UpdateGameViewModel()
        {
            var game = new GameDto
            {
                Id             = 1,
                LanguagesNames = new Dictionary <string, string> {
                    { "ru", "name" }
                },
                LanguagesDescriptions = new Dictionary <string, string> {
                    { "ru", "description" }
                },
                PlatformTypes = new List <PlatformTypeDto> {
                    new PlatformTypeDto(1, "type")
                },
                Publishers = new List <PublisherDto> {
                    new PublisherDto {
                        Id = 1
                    }
                },
                Genres = new List <GenreDto> {
                    new GenreDto(1, "name", null)
                },
                Price        = 10,
                UnitsInStock = 5,
                Discounted   = false
            };

            UpdateGameViewModel result = game.ToUpdateViewModel();

            Assert.AreEqual(game.Id, result.GameId);
            Assert.AreEqual(game.Price, result.Price);
            Assert.AreEqual(game.UnitsInStock, result.UnitsInStock);
            Assert.AreEqual(game.LanguagesNames.Values.First(), result.Name);
            Assert.AreEqual(game.LanguagesDescriptions.Values.First(), result.Description);
            Assert.AreEqual(game.PlatformTypes.Count, result.PlatformTypeIds.Count);
            Assert.AreEqual(game.Publishers.Count, result.PublisherIds.Count);
            Assert.AreEqual(game.Genres.Count, result.GenreIds.Count);
            Assert.AreEqual(false, result.IsContainEnglishTranslation);
            Assert.AreEqual(string.Empty, result.EnglishName);
            Assert.AreEqual(string.Empty, result.EnglishDescription);
        }
Beispiel #6
0
        public async Task <JsonResult> UpdateGame(string id, [FromBody] UpdateGameViewModel updatePayload, CancellationToken cancellationToken)
        {
            var updatedGame = await _mediator.Send(new UpdateGameRequest { Id = id, Player = updatePayload.Player, MoveCoordinate = updatePayload.MoveCoordinate }, cancellationToken);

            return(updatedGame.JsonResult());
        }