public IEnumerable <Contribution> GetContributionsByContributorID(int contributorId) { var sManager = new SimchaManager(_connectionString); using (var connection = new SqlConnection(_connectionString)) using (var cmd = connection.CreateCommand()) { cmd.CommandText = "SELECT * from Contributions " + "WHERE ContributorId = @contributorId"; cmd.Parameters.AddWithValue("@contributorId", contributorId); connection.Open(); var contributions = new List <Contribution>(); var reader = cmd.ExecuteReader(); while (reader.Read()) { var contribution = new Contribution { SimchaId = (int)reader["SimchaId"], ContributorId = (int)reader["ContributorId"], Amount = (decimal)reader["ContributionAmount"] }; var simcha = sManager.GetSimchaById(contribution.SimchaId); contribution.SimchaName = simcha.SimchaName; contribution.SimchaDate = simcha.Date; contributions.Add(contribution); } return(contributions); } }
public void AddContribution(Contribution contribution) { using (var sqlConnection = new SqlConnection(_connectionString)) using (var cmd = sqlConnection.CreateCommand()) { sqlConnection.Open(); cmd.CommandText = "INSERT INTO Contributions " + "VALUES (@simchaId, @contributorId, @contributionAmount)"; cmd.Parameters.AddWithValue("@simchaId", contribution.SimchaId); cmd.Parameters.AddWithValue("@contributorId", contribution.ContributorId); cmd.Parameters.AddWithValue("@contributionAmount", contribution.Amount); cmd.ExecuteNonQuery(); } }