public ActionResult Deposit(Deposit deposit)
 {
     var mgr = new SimchaFundManager(Properties.Settings.Default.ConStr);
     mgr.AddDeposit(deposit);
     TempData["Message"] = "Deposit of $" + deposit.Amount + " recorded successfully";
     return RedirectToAction("Index");
 }
 public ActionResult New(Contributor contributor, decimal initialDeposit)
 {
     var mgr = new SimchaFundManager(Properties.Settings.Default.ConStr);
     mgr.AddContributor(contributor);
     var deposit = new Deposit
     {
         Amount = initialDeposit,
         ContributorId = contributor.Id,
         Date = contributor.Date
     };
     mgr.AddDeposit(deposit);
     TempData["Message"] = "New Contributor Created! Id: " + contributor.Id;
     return RedirectToAction("index");
 }
        public IEnumerable<Deposit> GetDepositsById(int contribId)
        {
            List<Deposit> deposits = new List<Deposit>();
            using (var connection = new SqlConnection(_connectionString))
            using (var cmd = connection.CreateCommand())
            {
                cmd.CommandText = "SELECT * FROM Deposits WHERE ContributorId = @contribId";
                cmd.Parameters.AddWithValue("@contribId", contribId);
                connection.Open();
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Deposit deposit = new Deposit();
                    deposit.Id = (int)reader["Id"];
                    deposit.Amount = (decimal)reader["Amount"];
                    deposit.Date = (DateTime)reader["Date"];
                    deposits.Add(deposit);
                }
            }

            return deposits;
        }
 public void AddDeposit(Deposit deposit)
 {
     using (var connection = new SqlConnection(_connectionString))
     using (var cmd = connection.CreateCommand())
     {
         cmd.CommandText = @"INSERT INTO Deposits (Date, Amount, ContributorId)
                              VALUES (@date, @amount, @contributorId)";
         cmd.Parameters.AddWithValue("@date", deposit.Date);
         cmd.Parameters.AddWithValue("@amount", deposit.Amount);
         cmd.Parameters.AddWithValue("@contributorId", deposit.ContributorId);
         connection.Open();
         cmd.ExecuteNonQuery();
     }
 }