public ActionResult UpdateGame(string gameKey) { GameDto game = _gameService.GetGameByKey(gameKey); if (game.Deleted) { throw new GameDeletedException(); } IEnumerable <PlatformTypeDto> platformTypes = _platformTypeService.GetAllPlatformTypes(); var platformTypesMultiselect = new MultiSelectList(platformTypes, "Id", "Type"); IEnumerable <PublisherDto> publishers = _publisherService.GetAllPublishers(); var publishersMultiselect = new MultiSelectList(publishers, "Id", "CompanyName"); IEnumerable <GenreDto> genres = _genreService.GetAllGenres(); var genresMultiselect = new MultiSelectList(genres, "Id", "Name"); var model = game.ToUpdateViewModel(); model.AllPlatformTypes = platformTypesMultiselect; model.AllGenres = genresMultiselect; model.AllPublishers = publishersMultiselect; return(View(model)); }
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); }