コード例 #1
0
 public void AddDeposit(Contributor contr)
 {
     using (SqlConnection conn = new SqlConnection(_conStr))
         using (SqlCommand cmd = conn.CreateCommand())
         {
             cmd.CommandText = @"INSERT INTO Deposits(ContributorId, DepositAmount, DepositDate)
                             VALUES(@id, @amount, @date)";
             cmd.Parameters.AddWithValue("@id", contr.ContributorId);
             cmd.Parameters.AddWithValue("@amount", contr.DepositAmount);
             cmd.Parameters.AddWithValue("@date", contr.DepositDate);
             conn.Open();
             cmd.ExecuteNonQuery();
         }
 }
コード例 #2
0
        public Contributor GetHistoryById(int contrId)
        {
            var contributor = new Contributor();

            contributor.Transactions.AddRange(GetDepositsById(contrId));
            contributor.Transactions.AddRange(GetContributionsById(contrId));
            contributor.Transactions = contributor.Transactions.OrderByDescending(trans => trans.Date).ToList();
            foreach (Transaction trans in contributor.Transactions)
            {
                contributor.Balance += trans.Amount;
            }
            contributor.FirstName = GetContributorById(contrId).FirstName;
            contributor.LastName  = GetContributorById(contrId).LastName;
            return(contributor);
        }
コード例 #3
0
 public void UpdateContributor(Contributor contr)
 {
     using (var conn = new SqlConnection(_conStr))
         using (var cmd = conn.CreateCommand())
         {
             cmd.CommandText = @"UPDATE Contributors SET FirstName = @firstname, LastName = @lastName, 
                             PhoneNumber = @phoneNumber, AlwaysInclude = @alwaysInclude
                             WHERE ContributorId = @id";
             cmd.Parameters.AddWithValue("@firstname", contr.FirstName);
             cmd.Parameters.AddWithValue("@lastName", contr.LastName);
             cmd.Parameters.AddWithValue("@phoneNumber", contr.PhoneNumber);
             cmd.Parameters.AddWithValue("@alwaysInclude", contr.AlwaysInclude);
             cmd.Parameters.AddWithValue("@id", contr.ContributorId);
             conn.Open();
             cmd.ExecuteNonQuery();
         }
 }
コード例 #4
0
 public void AddContributor(Contributor contr)
 {
     using (var conn = new SqlConnection(_conStr))
         using (var cmd = conn.CreateCommand())
         {
             cmd.CommandText = @"INSERT INTO Contributors(FirstName, LastName, PhoneNumber, AlwaysInclude)
                             VALUES(@firstname, @lastname, @phonenumber, @include)
                             SELECT SCOPE_IDENTITY()";
             cmd.Parameters.AddWithValue("@firstname", contr.FirstName);
             cmd.Parameters.AddWithValue("@lastname", contr.LastName);
             cmd.Parameters.AddWithValue("@phonenumber", contr.PhoneNumber);
             cmd.Parameters.AddWithValue("@include", contr.AlwaysInclude);
             conn.Open();
             contr.ContributorId = (int)(decimal)cmd.ExecuteScalar();
         }
     AddDeposit(contr);
 }