public void ShouldUpdateGame()
        {
            var model = new UpdateGameModel
            {
                Description                 = "Description",
                Discounted                  = false,
                EnglishDescription          = "EnglishDescription",
                EnglishName                 = "EnglishName",
                GameId                      = 1,
                GenreIds                    = new List <int>(),
                IsContainEnglishTranslation = true,
                Name            = "Name",
                PlatformTypeIds = new List <int>(),
                Price           = 10,
                PublisherIds    = new List <int>(),
                UnitsInStock    = 10
            };

            _gameService.Setup(m => m.Edit(It.IsAny <EditingGameDto>()));

            HttpResponseMessage response = _gamesController.Post(model);

            _gameService.Verify(m => m.Edit(It.IsAny <EditingGameDto>()), Times.AtLeastOnce);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 2
0
        public static EditingGameDto ToEditingDto(this UpdateGameModel 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 HttpResponseMessage Post([FromBody] UpdateGameModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            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(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 4
0
        public ActionResult Update(string gameKey)
        {
            Game game = _gameService.GetByKey(gameKey, CurrentLangCode);

            if (game == null)
            {
                throw new Exception("game with that key not found");
            }

            UpdateGameModel model = new UpdateGameModel();

            model.Game           = game;
            model.SelectedGenres = game.Genres != null?game.Genres.Select(a => a.Name).ToList() : null;

            model.SelectedPlatforms = game.Platforms != null?game.Platforms.Select(a => a.Name).ToList() : null;

            model.SelectedPublisher   = game.Publisher != null ? game.Publisher.CompanyName : null;
            model.AvailableGenres     = _genreService.GetAllItems();
            model.AvailablePlatforms  = _platformService.GetAllItems();
            model.AvailablePublishers = _publisherService.GetAllItems();
            model.languages           = _languageService.GetAllLanguages();

            GameLang gameLang = _languageService.GetGameLocalizations(game.Id).FirstOrDefault();

            if (gameLang != null)
            {
                model.LangCode = gameLang.Language.Code;
                model.additionalDescription = gameLang.Description;
            }
            return(View("Update", model));
        }
Esempio n. 5
0
        public ActionResult Update(UpdateGameModel model)
        {
            var game = model.Game;

            game.Genres    = null;
            game.Platforms = null;

            game.UnregisterPlatformFromGame();
            if (ModelState.IsValid)
            {
                _gameService.Update(game);
                _gameService.AddLocalizatedDescription(model.GameKey, model.LangCode, model.additionalDescription);
                if (model.SelectedGenres != null && model.SelectedGenres.Any())
                {
                    _genreService.SetForGame(model.Game.Key, model.SelectedGenres);
                }
                if (model.SelectedPlatforms != null && model.SelectedPlatforms.Any())
                {
                    _platformService.SetForGame(model.Game.Key, model.SelectedPlatforms);
                }
                if (!string.IsNullOrWhiteSpace(model.SelectedPublisher))
                {
                    _publisherService.SetForGame(model.Game.Key, model.SelectedPublisher);
                }
                return(RedirectToAction("AllGames"));
            }
            model.AvailableGenres     = _genreService.GetAllItems();
            model.AvailablePlatforms  = _platformService.GetAllItems();
            model.AvailablePublishers = _publisherService.GetAllItems();
            model.languages           = _languageService.GetAllLanguages();
            return(View(model));
        }
Esempio n. 6
0
 public IActionResult Update([FromBody] UpdateGameModel model)
 {
     if (_gameService.Update(model.GameId, model.Game))
     {
         return(Ok());
     }
     return(BadRequest());
 }
Esempio n. 7
0
        public HttpResponseMessage Post([FromBody] UpdateGameModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            _gameService.Edit(model.ToEditingDto());

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 8
0
        public async Task <ActionResult <GameViewModel> > UpdateGame(UpdateGameModel model)
        {
            var result = await _mediator.Send(new UpdateGame
            {
                Id          = model.Id,
                Name        = model.Name,
                Description = model.Description
            });

            return(result != null ? new ActionResult <GameViewModel>(result) : BadRequest());
        }
Esempio n. 9
0
        public async Task <ActionResult> UpdateGameModal(UpdateGameModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await GameWriter.UpdateGame(model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View(model));
            }

            return(CloseModalSuccess());
        }
Esempio n. 10
0
        public async Task <IWriterResult> UpdateGame(UpdateGameModel model)
        {
            using (var context = DataContextFactory.CreateContext())
            {
                var game = await context.Games.FirstOrDefaultAsync(x => x.Id == model.Id);

                if (game == null)
                {
                    return(new WriterResult(false, "Game not found"));
                }

                if (game.Status == Enums.GameStatus.Deleted)
                {
                    return(new WriterResult(false, "Unable to update deleted game"));
                }

                // if name has changed, check for duplicates
                if (!game.Name.Equals(model.Name, StringComparison.OrdinalIgnoreCase))
                {
                    if (await GameNameExists(context, model.Name))
                    {
                        return(new WriterResult(false, "Game with name already exists"));
                    }

                    game.Name = model.Name;
                }

                if (game.Status != model.Status)
                {
                    if (game.Status == Enums.GameStatus.Finished && model.Status != Enums.GameStatus.Deleted)
                    {
                        return(new WriterResult(false, $"Finished game cannot be set to {model.Status} status"));
                    }
                }

                game.Rank            = model.Rank;
                game.Status          = model.Status;
                game.Platform        = model.Platform;
                game.Description     = model.Description;
                game.ClicksPerSecond = model.ClicksPerSecond;

                await context.SaveChangesAsync();

                return(new WriterResult(true));
            }
        }
Esempio n. 11
0
        public async Task <IActionResult> PutGame(int id, [FromBody] UpdateGameModel game)
        {
            if (id != game.ID)
            {
                return(BadRequest());
            }

            string userID = User.FindFirst(c => c.Type == "UserID").Value;

            var query  = new UpdateGameQuery(game, userID);
            var result = await _mediator.Send(query);

            if (result == true)
            {
                return(Ok("Successfully updated"));
            }

            return(BadRequest("Something went wrong while trying to update your game"));
        }
 public UpdateGameQuery(UpdateGameModel model, string userID)
 {
     UpdateGameModel = model;
     UserID          = userID;
 }