Example #1
0
        public List<Backing> FindAll()
        {
            List<Backing> Backings = new List<Backing>();
            string query = "SELECT * FROM Backing";

            using (SqlConnection db = new SqlConnection(CONN_STR))
            {
                if (db.State != System.Data.ConnectionState.Open)
                {
                    db.Open();
                }

                using (SqlCommand cmd = db.CreateCommand())
                {
                    cmd.CommandText = query;

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Backing b = new Backing();
                            b.BackingID = reader.GetInt32(reader.GetOrdinal("BackingID"));
                            b.UserID = reader.GetInt32(reader.GetOrdinal("UserID"));
                            b.ProjectID = reader.GetInt32(reader.GetOrdinal("ProjectID"));
                            b.BackingAmount = reader.GetInt32(reader.GetOrdinal("BackingAmount"));
                            b.BackingDate = reader.GetDateTime(reader.GetOrdinal("BackingDate"));

                            Backings.Add(b);
                        }
                    }
                }
            }
            return Backings;
        }
Example #2
0
        public void Delete(Backing backing)
        {
            string query = "DELETE FROM Backing";

            using (SqlConnection db = new SqlConnection(CONN_STR))
            {
                if (db.State != System.Data.ConnectionState.Open)
                {
                    db.Open();
                }

                using (SqlCommand cmd = db.CreateCommand())
                {
                    cmd.CommandText = query;
                    cmd.ExecuteNonQuery();
                }
            }
        }
Example #3
0
        public Backing Save(Backing backing)
        {
            string query = @"INSERT INTO Backing (
                                UserID, 
                                ProjectID,
                                BackingAmount,
                                BackingDate
                            ) VALUES (
                                @UserID,
                                @ProjectID,
                                @BackingAmount,
                                @BackingDate
                            )";

            using (SqlConnection db = new SqlConnection(CONN_STR))
            {
                if (db.State != System.Data.ConnectionState.Open)
                {
                    db.Open();
                }

                using (SqlCommand cmd = db.CreateCommand())
                {
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("UserID", backing.UserID);
                    cmd.Parameters.AddWithValue("ProjectID", backing.ProjectID);
                    cmd.Parameters.AddWithValue("BackingAmount", backing.BackingAmount);
                    cmd.Parameters.AddWithValue("BackingDate", backing.BackingDate);
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "SELECT @@Identity";
                    backing.BackingID = (int)(decimal)cmd.ExecuteScalar();
                }
            }

            return backing;
        }
Example #4
0
        public ActionResult Back(int amount, int projectID, int userID)
        {
            Backing backing = new Backing();
            backing.BackingAmount = amount;
            backing.BackingDate = DateTime.Now;
            backing.ProjectID = projectID;
            backing.UserID = userID;
            BackingRepository.Save(backing);

            return RedirectToAction("Details", new { id = projectID });
        }