/// <summary> /// data layer will determine add vs update /// </summary> /// <param name="league"></param> public void Save(TeamPlayerLineupDto teamPlayerLineup) { if (ExistsInDb(teamPlayerLineup)) { Update(teamPlayerLineup); } else { AddNew(teamPlayerLineup); } }
public ChangeResult AddPlayerToLineup(Guid playerId) { TeamPlayerLineupDto dto = new TeamPlayerLineupDto() { TeamId = TeamId, PlayerId = playerId, BattingOrder = 999 }; return(TeamPlayerLineup.Save(dto)); }
public void InvalidPlayerIdTest() { TeamPlayerLineupDto dto = new TeamPlayerLineupDto() { TeamId = Guid.NewGuid(), BattingOrder = TEST_BATTING_ORDER }; var result = Lineup.AddNew(dto); Assert.IsFalse(result.IsSuccess); }
public bool ExistsInDb(TeamPlayerLineupDto teamPlayerLineup) { Connection.BeginTransaction(); var rows = Connection.Query <int>(@"SELECT COUNT(1) as 'Count' FROM TeamPlayerLineup WHERE PlayerId = @PlayerId AND TeamId = @TeamId", new { teamPlayerLineup.PlayerId, teamPlayerLineup.TeamId }); Connection.Commit(); return(rows.First() > 0); }
private void UpdateTeamPlayerLineup(TeamPlayerLineupDto teamPlayerLineup) { string updateQuery = @"UPDATE TeamPlayerLineup SET TeamPlayerLineupId = @TeamPlayerLineupId, PlayerId = @PlayerId, TeamId = @TeamId, BattingOrder = @BattingOrder, DeleteDate = @DeleteDate WHERE PlayerId = @PlayerId AND TeamId = @TeamId"; Connection.BeginTransaction(); Connection.Execute(updateQuery, teamPlayerLineup); Connection.Commit(); }
private void InsertTeamPlayerLineup(TeamPlayerLineupDto teamPlayerLineup) { string insertQuery = @"INSERT INTO TeamPlayerLineup (TeamPlayerLineupId, TeamId, PlayerId, BattingOrder, DeleteDate) VALUES( @TeamPlayerLineupId, @TeamId, @PlayerId, @BattingOrder, @DeleteDate)"; Connection.BeginTransaction(); Connection.Execute(insertQuery, teamPlayerLineup); Connection.Commit(); }
public void AddUpdateTeamPlayerLineupTest() { Guid seedTeamId = SeedTeam(); Guid seedPlayerId = SeedPlayer(); TeamPlayerLineupDto dto = new TeamPlayerLineupDto() { TeamId = seedTeamId, PlayerId = seedPlayerId, BattingOrder = TEST_BATTING_ORDER }; var addResult = Lineup.AddNew(dto); Assert.IsTrue(addResult.IsSuccess); var teamPlayerLineupItem = Lineup.GetTeamPlayerLineupItem(seedTeamId, seedPlayerId); Assert.IsNotNull(teamPlayerLineupItem); Assert.IsFalse(teamPlayerLineupItem.TeamPlayerLineupId == Guid.Empty); Assert.AreEqual(teamPlayerLineupItem.TeamId, seedTeamId); Assert.AreEqual(teamPlayerLineupItem.PlayerId, seedPlayerId); dto.TeamPlayerLineupId = teamPlayerLineupItem.TeamPlayerLineupId; dto.BattingOrder = TEST_BATTING_ORDER_2; var updateResult = Lineup.Update(dto); Assert.IsTrue(updateResult.IsSuccess); teamPlayerLineupItem = Lineup.GetTeamPlayerLineupItem(seedTeamId, seedPlayerId); Assert.IsNotNull(teamPlayerLineupItem); Assert.AreEqual(TEST_BATTING_ORDER_2, teamPlayerLineupItem.BattingOrder); var teamLineup = Lineup.GetTeamLineup(seedTeamId); Assert.IsTrue(teamLineup.Count >= 1); var removeResult = Lineup.Remove(seedTeamId, seedPlayerId); Assert.IsTrue(removeResult.IsSuccess); teamPlayerLineupItem = Lineup.GetTeamPlayerLineupItem(seedTeamId, seedPlayerId); Assert.IsNull(teamPlayerLineupItem); DeleteSeededTeam(seedTeamId); DeleteSeededPlayer(seedPlayerId); }
public TeamPlayerLineupDto LoadByCompositeKey(Guid playerId, Guid teamId) { TeamPlayerLineupDto teamPlayerLineup = null; Connection.BeginTransaction(); var result = Connection.Query <TeamPlayerLineupDto>( SELECT_QUERY + " WHERE PlayerId = @PlayerId " + "AND TeamId = @TeamId", new { PlayerId = playerId.ToString(), TeamId = teamId.ToString() }); teamPlayerLineup = result.FirstOrDefault(); Connection.Commit(); return(teamPlayerLineup); }
public void SeedTeamPlayerLineup(Guid teamId, List <Guid> sortedPlayerIds) { int battingOrder = 0; List <ITeamPlayerLineup> teamPlayers = new List <ITeamPlayerLineup>(); foreach (Guid playerId in sortedPlayerIds) { TeamPlayerLineupDto dto = new TeamPlayerLineupDto() { BattingOrder = battingOrder, PlayerId = playerId, TeamId = teamId }; teamPlayers.Add(dto); battingOrder++; } TeamPlayerLineup.AddNew(teamPlayers); }
public void Update(TeamPlayerLineupDto teamPlayerLineup) { UpdateTeamPlayerLineup(teamPlayerLineup); }
public void AddNew(TeamPlayerLineupDto teamPlayerLineup) { InsertTeamPlayerLineup(teamPlayerLineup); }