예제 #1
0
 /// <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);
     }
 }
예제 #2
0
        public ChangeResult AddPlayerToLineup(Guid playerId)
        {
            TeamPlayerLineupDto dto = new TeamPlayerLineupDto()
            {
                TeamId       = TeamId,
                PlayerId     = playerId,
                BattingOrder = 999
            };

            return(TeamPlayerLineup.Save(dto));
        }
예제 #3
0
        public void InvalidPlayerIdTest()
        {
            TeamPlayerLineupDto dto = new TeamPlayerLineupDto()
            {
                TeamId       = Guid.NewGuid(),
                BattingOrder = TEST_BATTING_ORDER
            };

            var result = Lineup.AddNew(dto);

            Assert.IsFalse(result.IsSuccess);
        }
예제 #4
0
        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);
        }
예제 #5
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();
        }
예제 #6
0
        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();
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
 public void Update(TeamPlayerLineupDto teamPlayerLineup)
 {
     UpdateTeamPlayerLineup(teamPlayerLineup);
 }
예제 #11
0
 public void AddNew(TeamPlayerLineupDto teamPlayerLineup)
 {
     InsertTeamPlayerLineup(teamPlayerLineup);
 }