public Result <PlayedGameDto> GetGame(int gameId) { Result <PlayedGameDto> result = new Result <PlayedGameDto>(); try { PlayedGameDto gameDto = this.gamesRepository.Find(gameId); if (gameDto == null) { result.SetError($"There is no game with #{ gameId }!"); return(result); } var dataSourcesResult = this.dataSourceService.GetPlayedGameDataSources(); if (dataSourcesResult.IsError) { result.SetError(dataSourcesResult.Message); return(result); } var dataSources = dataSourcesResult.Data; gameDto = this.FillGameAdditionalData(dataSources, gameDto); return(result.SetData(gameDto)); } catch (Exception ex) { result.SetError(ex.Message); return(result); } }
public Result DeleteGame(int gameId) { Result result = new Result(); try { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { PlayedGameDto gameDto = this.gamesRepository.Find(gameId); if (gameDto == null) { return(result.SetError($"There is no game with #{ gameId }!")); } this.gamesRepository.Delete(gameDto.ID); UpdatePlayedGameDto deletedGame = Mapper.Map <PlayedGameDto, UpdatePlayedGameDto>(gameDto); Result updateTeamPointsResult = this.UpdateTeamsPoints(deletedGame, gameDeletion: true); if (updateTeamPointsResult.IsError) { return(updateTeamPointsResult); } scope.Complete(); } return(result.SetSuccess("Game deleted.")); } catch (Exception ex) { return(result.SetError(ex.Message)); } }
public Result <PlayedGameDto> AddPlayedGame(AddPlayedGameDto gameDto) { Result <PlayedGameDto> result = new Result <PlayedGameDto>(); try { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { gameDto.DatePlayed = this.dateTimeProvider.GetCurrentDateTime(); PlayedGameDto newGameDto = this.gamesRepository.AddGame(gameDto); UpdatePlayedGameDto addedGame = Mapper.Map <PlayedGameDto, UpdatePlayedGameDto>(newGameDto); Result updatePointsResult = this.UpdateTeamsPoints(addedGame, gameDeletion: false); if (updatePointsResult.IsError) { result.SetError(updatePointsResult.Message); return(result); } scope.Complete(); return(result.SetData(newGameDto)); } } catch (Exception ex) { result.SetError(ex.Message); return(result); } }
public virtual PlayedGameDto Find(params object[] keys) { PlayedGame game = this.DbSet.Find(keys); PlayedGameDto gameDto = Mapper.Map <PlayedGame, PlayedGameDto>(game); return(gameDto); }
public PlayedGameDto AddGame(AddPlayedGameDto gameToAdd) { PlayedGame game = Mapper.Map <AddPlayedGameDto, PlayedGame>(gameToAdd); this.context.PlayedGames.Add(game); this.context.SaveChanges(); PlayedGameDto addedGame = Mapper.Map <PlayedGame, PlayedGameDto>(game); return(addedGame); }
private PlayedGameDto FillGameAdditionalData(PlayedGameDataSourcesDto dataSources, PlayedGameDto gameDto) { gameDto.HomeTeamName = dataSources.Teams[gameDto.HomeTeamId].Name; gameDto.AwayTeamName = dataSources.Teams[gameDto.AwayTeamId].Name; gameDto.ResultName = dataSources.Results[(int)gameDto.Result].Name; return(gameDto); }