Beispiel #1
0
        // Add new team to database. Team object receieves a TeamID
        public void AddTeam(Team team)
        {
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var p = new DynamicParameters();

                try
                {
                    p.Add("TeamName", team.TeamName);
                    p.Add("ManagerName", team.ManagerName);
                    p.Add("LeagueID", team.LeagueID);
                    p.Add("TeamID", DbType.Int32, direction: ParameterDirection.Output);

                    cn.Execute("CreateTeam", p, commandType: CommandType.StoredProcedure);

                    team.TeamID = p.Get<int>("TeamID");
                }
                //catch (Exception e)
                //{
                //    var ep = new DynamicParameters();

                //    ep.Add("ExceptionType", e.GetType());
                //    ep.Add("ExceptionMessage", e.Message);
                //    ep.Add("Input", String.Format("TeamName = {0}, ManagerName = {1}, LeagueID = {2}",
                //        team.TeamName, team.ManagerName, team.LeagueID));
                //    cn.Execute("AddError", ep, commandType: CommandType.StoredProcedure);
                //}
                finally
                {
                    cn.Close();
                }
            }
        }
Beispiel #2
0
        public int AddTeam(Team team)
        {
            int teamId;

            using (var connection = new SqlConnection(Settings.ConnectionString))
            {
                var command = new SqlCommand();
                command.CommandText = "SP_AddTeam";
                command.CommandType = CommandType.StoredProcedure;

                var outputParam = new SqlParameter("@TeamID", SqlDbType.Int) { Direction = ParameterDirection.Output };

                command.Connection = connection;
                command.Parameters.AddWithValue("@TeamName", team.TeamName);
                command.Parameters.AddWithValue("@ManagerName", team.ManagerName);
                command.Parameters.Add(outputParam);
                connection.Open();

                command.ExecuteNonQuery();

                teamId = (int)outputParam.Value;
            }

            return teamId;
        }
        public void AddTeamTest()
        {
            var team = new Team();
            team.TeamName = "CloudRiders";
            team.Manager = "Genos";
            team.League.LeagueID = 2;

            var response = _ops.AddTeam(team);

            Assert.AreEqual(true, response.Success);
        }
Beispiel #4
0
 public Response()
 {
     League = new League();
     Leagues = new List<League>();
     Team = new Team();
     Teams = new List<Team>();
     Position = new Position();
     Positions = new List<Position>();
     Player = new Player();
     Players = new List<Player>();
 }
        public Team AddTeam(Team team)
        {
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var pnsm = new DynamicParameters();
                pnsm.Add("@TeamName", team.TeamName);
                pnsm.Add("@Manager", team.Manager);
                pnsm.Add("@LeagueID", team.League.LeagueID);
                pnsm.Add("@TeamID", DbType.Int32, direction: ParameterDirection.Output);

                cn.Execute("InsertTeams", pnsm, commandType: CommandType.StoredProcedure);

                var teamID = pnsm.Get<int>("TeamID");

                return GetTeamByID(teamID);
            }
        }
 public int AddTeam(Team t)
 {
     using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
     {
         var sqlQuery = "INSERT INTO Team (TeamName,Manager,LeagueID) " +
                        "VALUES (@TeamName,@Manager,@LeagueID) "+
                        "SELECT SCOPE_IDENTITY() AS id";
             int teamId = cn.Query<int>(sqlQuery,
                 new
                 {
                     t.TeamName,
                     t.Manager,
                     t.LeagueId
                 }).FirstOrDefault();
         return teamId;
     }
 }
        public void AddTeam()
        {
            var team = new Team();
            team.TeamName = "Cloud Riders";
            team.Manager = "Genos";
            team.League.LeagueID = 2;

            var result = _repo.AddTeam(team);

            var expectedTeam = _repo.GetTeamByID(
                result.TeamID);

            var actual = _jss.Serialize(result);

            var expected = _jss.Serialize(expectedTeam);

            Assert.AreEqual(expected, actual);
        }
        public Response AddTeam(Team teamToAdd)
        {
            _response = new Response();

            var team = _repo.AddTeam(teamToAdd);

            if (team != null)
            {
                _response.Success = true;
                _response.Team = team;
            }
            else
            {
                _response.Success = false;
            }

            return _response;
        }
        private Team PopulateTeamInfoFromDataReader(SqlDataReader dr)
        {
            var team = new Team();

            team.TeamID = (int)dr["TeamID"];
            team.TeamName = dr["TeamName"].ToString();
            team.Manager = dr["Manager"].ToString();
            team.League.LeagueID = (int)dr["LeagueID"];

            return team;
        }
        public League GetTeamsByLeagueID(int leagueID)
        {
            League league = new League();
            Teams = new List<Team>();

            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand();
                cmd.CommandText = "GetTeamsByLeagueID";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Connection = cn;
                cmd.Parameters.AddWithValue("@LeagueID", leagueID);

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        league = PopulateLeagueInfoFromReader(dr);

                        Team team = new Team();
                        team.TeamID = (int)dr["TeamID"];
                        team.League.LeagueID = (int)dr["leagueID"];
                        team.League.LeagueName = dr["leagueName"].ToString();
                        team.Manager = dr["Manager"].ToString();
                        team.TeamName = dr["TeamName"].ToString();

                        Teams.Add(team);
                        league.Teams = Teams;
                    }
                }
            }

            return league;
        }
        //public League GetTeamsByLeagueID(int leagueID)
        //{
        //    League league = new League();
        //    using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
        //    {
        //        var p = new DynamicParameters();
        //        p.Add("@LeagueID", leagueID);
        //        league = cn.Query<League>("GetTeamsByLeagueID", p, commandType: CommandType.StoredProcedure).FirstOrDefault();
        //    }
        //    return league;
        //}
        public Team GetTeamByID(int teamID)
        {
            Team team = new Team();

            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var p = new DynamicParameters();
                p.Add("@TeamID", teamID);

                team = cn.Query<Team>("GetTeamByID", p, commandType: CommandType.StoredProcedure).FirstOrDefault();
            }

            return team;
        }
Beispiel #12
0
 public Player()
 {
     Position = new Position();
     Team = new Team();
 }
 public TeamAndPlayersViewModel(Team t, List<Player> plist)
 {
     Team = t;
     Players = plist;
 }
 public TeamAndPlayersViewModel()
 {
     Team = new Team();
     Players = new List<Player>();
 }
 // Add new team to database. Team object receieves a TeamID
 public void AddTeam(Team team)
 {
     var create = new Create();
     create.AddTeam(team);
 }
 public void PostNewTeam(Team NewTeam)
 {
     var ops = new BaseballBLL();
     ops.AddTeam(NewTeam);
 }