public IEnumerable <Simcha> GetSimchas() { SqlConnection con = new SqlConnection(_connectionstring); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = @"Select s.id, s.Date, s.Name, ISNULL(SUM(SC.Amount),0) as Collected from SimchaContribution SC right join Simchas s on SC.Simchaid = s.id Group by s.id, s.Date, s.Name"; List <Simcha> simchas = new List <Simcha>(); con.Open(); SqlDataReader Reader = cmd.ExecuteReader(); while (Reader.Read()) { Simcha s = new Simcha { Id = (int)Reader["id"], Date = (DateTime)Reader["Date"], Name = (string)Reader["Name"], MRaised = (decimal)Reader["Collected"] }; s.TotalContributors = GetContributorsCount(s.Id); simchas.Add(s); } con.Close(); con.Close(); return(simchas); }
public void AddSimcha(Simcha s) { SqlConnection con = new SqlConnection(_connectionstring); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = @"insert into Simchas Values(@Name, @Date); "; cmd.Parameters.AddWithValue("@Name", s.Name); cmd.Parameters.AddWithValue("@Date", s.Date); con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); }