public static Affiliate Get(int personID) { string dsn = ConfigurationManager.ConnectionStrings["RJLouEntities"].ToString(); string sql = @" SELECT a.Person_ID, First_Name, Last_Name, Date_Of_Birth, Gender, Email, Race FROM Affiliate a INNER JOIN Person p ON a.Person_ID = p.Person_ID WHERE a.Person_ID = @PersonID"; using (SqlConnection conn = new SqlConnection(dsn)) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("PersonID", personID); SqlDataReader read = cmd.ExecuteReader(); if (read.Read()) { Affiliate result = new Affiliate() { PersonID = Convert.ToInt32(read["Person_ID"]), FirstName = read["First_Name"].ToString(), LastName = read["Last_Name"].ToString(), DateOfBirth = Convert.ToDateTime(read["Date_Of_Birth"]), Gender = read["Gender"].ToString(), Email = read["Email"].ToString(), Race = read["Race"].ToString() }; result.GetPhoneNumbers(); result.GetAddresses(); return result; } } return null; }
public static List<Affiliate> GetAffiliates() { string dsn = ConfigurationManager.ConnectionStrings["RJLouEntities"].ToString(); string sql = @" SELECT a.Person_ID, First_Name, Last_Name, Date_Of_Birth, Gender, Email, Race FROM Affiliate a INNER JOIN Person p ON a.Person_ID = p.Person_ID"; List<Affiliate> results = new List<Affiliate>(); using (SqlConnection conn = new SqlConnection(dsn)) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = CommandType.Text; SqlDataReader read = cmd.ExecuteReader(); while (read.Read()) { Affiliate newAffiliate = new Affiliate() { PersonID = Convert.ToInt32(read["Person_ID"]), FirstName = read["First_Name"].ToString(), LastName = read["Last_Name"].ToString(), DateOfBirth = Convert.ToDateTime(read["Date_Of_Birth"]), Gender = read["Gender"].ToString(), Email = read["Email"].ToString(), Race = read["Race"].ToString() }; newAffiliate.GetPhoneNumbers(); newAffiliate.GetAddresses(); results.Add(newAffiliate); } } return results; }