private static TeamDto GetTeam(PlayerTeamDto playerTeam) { return(new TeamDto() { id = playerTeam.id, email = playerTeam.email, name = playerTeam.name, area = playerTeam.area, shortName = playerTeam.shortName, tla = playerTeam.tla }); }
public ChangeResult SavePlayerTeam(Guid teamId) { PlayerTeamDto dto = new PlayerTeamDto() { PlayerId = Player.PlayerId, TeamId = teamId }; return(PlayerTeam.Save(dto)); }
/// <summary> /// data layer will determine add vs update /// </summary> /// <param name="playerTeam"></param> public void Save(PlayerTeamDto playerTeam) { if (ExistsInDb(playerTeam)) { Update(playerTeam); } else { AddNew(playerTeam); } }
public static List <PlayerTeamItemDto> Map(PlayerTeamDto playerTeam) { var lista = new List <PlayerTeamItemDto>(); var team = GetTeam(playerTeam); playerTeam.squad.ForEach(x => lista.Add(new PlayerTeamItemDto() { Player = x, Team = team })); return(lista); }
public void InvalidPlayerIdTest() { PlayerTeamDto dto = new PlayerTeamDto() { PlayerId = Guid.Empty, TeamId = Guid.NewGuid() }; var addResult = PlayerTeamService.AddNew(dto); Assert.IsFalse(addResult.IsSuccess); }
public void InvalidTeamPlayerIdTest() { PlayerTeamDto dto = new PlayerTeamDto() { PlayerId = Guid.NewGuid(), TeamId = Guid.Empty }; var result = PlayerTeamService.Update(dto); Assert.IsFalse(result.IsSuccess); }
public bool ExistsInDb(PlayerTeamDto playerTeam) { Connection.BeginTransaction(); var rows = Connection.Query <int>(@"SELECT COUNT(1) as 'Count' FROM PlayerTeam WHERE PlayerId = @PlayerId AND TeamId = @TeamId", new { playerTeam.PlayerId, playerTeam.TeamId }); Connection.Commit(); return(rows.First() > 0); }
private void UpdatePlayerTeam(PlayerTeamDto playerTeam) { string updateQuery = @"UPDATE PlayerTeam SET PlayerTeamId = @PlayerTeamId, PlayerId = @PlayerId, TeamId = @TeamId, DeleteDate = @DeleteDate WHERE PlayerId = @PlayerId AND TeamId = @TeamId"; Connection.BeginTransaction(); Connection.Execute(updateQuery, playerTeam); Connection.Commit(); }
private void InsertPlayerTeam(PlayerTeamDto playerTeam) { string insertQuery = @"INSERT INTO PlayerTeam (PlayerTeamId, PlayerId, TeamId, DeleteDate) VALUES( @PlayerTeamId, @PlayerId, @TeamId, @DeleteDate)"; Connection.BeginTransaction(); Connection.Execute(insertQuery, playerTeam); Connection.Commit(); }
public void AddUpdatePlayerTeamTest() { Guid seedTeamId = SeedTeam(); Guid seedPlayerId = SeedPlayer(); PlayerTeamDto dto = new PlayerTeamDto() { PlayerId = seedPlayerId, TeamId = seedTeamId }; var addResult = PlayerTeamService.AddNew(dto); Assert.IsTrue(addResult.IsSuccess); var playerTeam = PlayerTeamService.GetPlayerTeam(seedTeamId, seedPlayerId); Assert.IsNotNull(playerTeam); Assert.AreEqual(seedTeamId, playerTeam.TeamId); Assert.AreEqual(seedPlayerId, playerTeam.PlayerId); Assert.IsFalse(playerTeam.PlayerTeamId == Guid.Empty); dto.PlayerTeamId = playerTeam.PlayerTeamId; var updateResult = PlayerTeamService.Update(dto); Assert.IsTrue(updateResult.IsSuccess); var teamPlayers = PlayerTeamService.GetTeamPlayers(seedTeamId); Assert.IsTrue(teamPlayers.Count >= 1); var teamPlayerInfos = PlayerTeamService.GetTeamPlayerInformations(seedTeamId); Assert.IsTrue(teamPlayerInfos.Count >= 1); Assert.IsNotNull(teamPlayerInfos.FirstOrDefault().Name); var removeResult = PlayerTeamService.Remove(seedPlayerId, seedTeamId); Assert.IsTrue(removeResult.IsSuccess); playerTeam = PlayerTeamService.GetPlayerTeam(seedTeamId, seedPlayerId); Assert.IsNull(playerTeam); DeleteSeededTeam(seedTeamId); DeleteSeededPlayer(seedPlayerId); }
public PlayerTeamDto LoadByCompositeKey(Guid playerId, Guid teamId) { PlayerTeamDto playerTeam = null; Connection.BeginTransaction(); var result = Connection.Query <PlayerTeamDto>( SELECT_QUERY + " WHERE PlayerId = @PlayerId " + "AND TeamId = @TeamId", new { PlayerId = playerId.ToString(), TeamId = teamId.ToString() }); playerTeam = result.FirstOrDefault(); Connection.Commit(); return(playerTeam); }
public void Update(PlayerTeamDto playerTeam) { UpdatePlayerTeam(playerTeam); }
public void AddNew(PlayerTeamDto playerTeam) { InsertPlayerTeam(playerTeam); }