Ejemplo n.º 1
0
        public void Edit(EditingGameDto editingGame)
        {
            CheckGameTranslationArgumentsValidity(editingGame.LanguagesNames, editingGame.LanguagesDescriptions);

            Game game = GetNotDeletedGame(editingGame.GameId);

            ICollection <Genre> fullGenreTree;

            if (editingGame.GenreIds.Any())
            {
                ICollection <Genre> selectedGenres = GetGenresFromIds(editingGame.GenreIds);
                fullGenreTree = BuildGenreTree(selectedGenres);
            }
            else
            {
                fullGenreTree = new List <Genre> {
                    GetDefaultGenre()
                };
            }

            MapperToModel.MapToModel(
                editingGame,
                game,
                GetPublishersFromIds(editingGame.PublisherIds),
                GetPlatformTypesFromIds(editingGame.PlatformTypeIds),
                fullGenreTree);

            SetTranslationsForGame(game, editingGame.LanguagesNames, editingGame.LanguagesDescriptions);

            UnitOfWork.Games.Update(game);
            UnitOfWork.Save();
        }
Ejemplo n.º 2
0
        public int Create(CreatingGameDto creatingGame)
        {
            CheckGameTranslationArgumentsValidity(creatingGame.LanguagesNames, creatingGame.LanguagesDescriptions);

            ICollection <Genre> fullGenreTree;

            if (creatingGame.GenreIds.Any())
            {
                ICollection <Genre> selectedGenres = GetGenresFromIds(creatingGame.GenreIds);
                fullGenreTree = BuildGenreTree(selectedGenres);
            }
            else
            {
                fullGenreTree = new List <Genre> {
                    GetDefaultGenre()
                };
            }

            Game game = UnitOfWork.Games.SingleOrDefaultDeleted(g => g.Key == creatingGame.Key);

            if (game == null)
            {
                game = new Game {
                    Key = creatingGame.Key
                };

                MapperToModel.MapToModel(
                    creatingGame,
                    game,
                    GetPublishersFromIds(creatingGame.PublisherIds),
                    GetPlatformTypesFromIds(creatingGame.PlatformTypeIds),
                    fullGenreTree.ToList());

                AddTranslationsToGame(game, creatingGame.LanguagesNames, creatingGame.LanguagesDescriptions);

                UnitOfWork.Games.Create(game);
            }
            else
            {
                MapperToModel.MapToModel(
                    creatingGame,
                    game,
                    GetPublishersFromIds(creatingGame.PublisherIds),
                    GetPlatformTypesFromIds(creatingGame.PlatformTypeIds),
                    fullGenreTree.ToList());

                SetTranslationsForGame(game, creatingGame.LanguagesNames, creatingGame.LanguagesDescriptions);

                UnitOfWork.Games.Update(game);
            }

            UnitOfWork.Save();

            return(game.Id);
        }