public JsonResult<ResponseViewModel<IntegrationGameViewModel>> PostIntegrationGame(NewIntegrationGameViewModel game) { var response = ServiceExecutor.Execute( () => _managementIntegrationGamesService.InsertIntegrationGame(game)); return Json(response); }
private bool ValidateInsertIntegrationGame(NewIntegrationGameViewModel game) { if (IsGameExists(game)) throw new Exception(ThrowMessage.GameExists.ToString()); return IsMainGameTranslation(game) ? InsertMainGameTranslation(game) : InsertAnotherGameTranslation(game); }
public IntegrationGameViewModel InsertIntegrationGame(NewIntegrationGameViewModel game) { if (!ValidateInsertIntegrationGame(game)) throw new Exception(ThrowMessage.JokeNotAdded.ToString()); return ValidateGetInsertedGame(game); }
private bool PutGameTranslation(NewIntegrationGameViewModel game) { var gameToEdit = ValidateGetIntegrationGameDetailById(game.IntegrationGameId); gameToEdit.IntegrationGameName = game.GameName; gameToEdit.IntegrationGameDescription = game.GameDetails; RepositoryFactory.Context.SaveChanges(); return true; }
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); }
private bool IsGameExists(NewIntegrationGameViewModel game) { return RepositoryFactory.Context.IntegrationGameDetails.Any(x => x.IntegrationGameName.Equals(game.GameName)); }
private bool IsMainGameTranslation(NewIntegrationGameViewModel game) { return game.Id == 0; }
private bool IsAnotherGameTranslation(NewIntegrationGameViewModel game) { return game.IntegrationGameId != 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; }
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; }
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()); }
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 }; }