コード例 #1
0
 public JsonResult<ResponseViewModel<IntegrationGameViewModel>> PostIntegrationGame(NewIntegrationGameViewModel game)
 {
     var response =
         ServiceExecutor.Execute(
             () => _managementIntegrationGamesService.InsertIntegrationGame(game));
     return Json(response);
 }
コード例 #2
0
 private bool ValidateInsertIntegrationGame(NewIntegrationGameViewModel game)
 {
     if (IsGameExists(game))
         throw new Exception(ThrowMessage.GameExists.ToString());
     return IsMainGameTranslation(game) ? InsertMainGameTranslation(game) : InsertAnotherGameTranslation(game);
 }
コード例 #3
0
 public IntegrationGameViewModel InsertIntegrationGame(NewIntegrationGameViewModel game)
 {
     if (!ValidateInsertIntegrationGame(game))
         throw new Exception(ThrowMessage.JokeNotAdded.ToString());
     return ValidateGetInsertedGame(game);
 }
コード例 #4
0
 private bool PutGameTranslation(NewIntegrationGameViewModel game)
 {
     var gameToEdit = ValidateGetIntegrationGameDetailById(game.IntegrationGameId);
     gameToEdit.IntegrationGameName = game.GameName;
     gameToEdit.IntegrationGameDescription = game.GameDetails;
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #5
0
 private IntegrationGameViewModel ValidateGetInsertedGame(NewIntegrationGameViewModel game)
 {
     var insertedGame = RepositoryFactory.Context.IntegrationGameDetails.FirstOrDefault(
                 x => x.IntegrationGameName.Equals(game.GameName));
     if (insertedGame == null)
         throw new Exception(ThrowMessage.GameNotExists.ToString());
     return IsMainGameTranslation(game)
         ? GetInsertedMainGame(insertedGame)
         : GetInsertedAnotherGame(insertedGame);
 }
コード例 #6
0
 private bool IsGameExists(NewIntegrationGameViewModel game)
 {
     return RepositoryFactory.Context.IntegrationGameDetails.Any(x => x.IntegrationGameName.Equals(game.GameName));
 }
コード例 #7
0
 private bool IsMainGameTranslation(NewIntegrationGameViewModel game)
 {
     return game.Id == 0;
 }
コード例 #8
0
 private bool IsAnotherGameTranslation(NewIntegrationGameViewModel game)
 {
     return game.IntegrationGameId != 0;
 }
コード例 #9
0
 private bool InsertMainGameTranslation(NewIntegrationGameViewModel game)
 {
     IntegrationGameDao entity = new IntegrationGameDao
     {
         CreationDate = DateTime.UtcNow,
         IntegrationGameDetails = new List<IntegrationGameDetailDao>()
     };
     entity.IntegrationGameDetails.Add(BuildIntegrationGameDetail(game));
     RepositoryFactory.Context.IntegrationGames.Add(entity);
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #10
0
 private bool InsertAnotherGameTranslation(NewIntegrationGameViewModel game)
 {
     if (IsAnotherGameTranslation(game))
     {
         return PutGameTranslation(game);
     }
     CheckIsTranslationForThisLanguageExists(game);
     var entity = RepositoryFactory.Context.IntegrationGames.FirstOrDefault(x => x.Id == game.Id);
     var gameDetails = BuildIntegrationGameDetail(game);
     if (!gameDetails.IntegrationGameFeatures.Any())
         throw new Exception(ThrowMessage.GameFeatureTranslationNotExists.ToString());
     entity?.IntegrationGameDetails.Add(gameDetails);
     RepositoryFactory.Context.SaveChanges();
     return true;
 }
コード例 #11
0
 private void CheckIsTranslationForThisLanguageExists(NewIntegrationGameViewModel game)
 {
     if (
         RepositoryFactory.Context.IntegrationGameDetails.Any(
             x => x.IntegrationGame.Id == game.Id && x.Language.Id == game.Language))
         throw new Exception(ThrowMessage.GameHaveTranslationForThisLanguage.ToString());
 }
コード例 #12
0
 private IntegrationGameDetailDao BuildIntegrationGameDetail(NewIntegrationGameViewModel game)
 {
     List<IntegrationGameFeatureDao> integrationGameFeatures = GetGameFeatures(game.Features, game.Language);
     if (integrationGameFeatures == null)
         return null;
     return new IntegrationGameDetailDao
     {
         Language = GetLanguage(game.Language),
         IntegrationGameName = game.GameName,
         IntegrationGameDescription = game.GameDetails,
         IntegrationGameFeatures = integrationGameFeatures
     };
 }