public List <SalesSpecial> GetSpecials()
        {
            List <SalesSpecial> specials = new List <SalesSpecial>();

            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("GetSpecials", cn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var special = new SalesSpecial();
                        special.SpecialID          = (int)dr["SpecialID"];
                        special.SpecialTitle       = dr["SpecialTitle"].ToString();
                        special.SpecialDescription = dr["SpecialDescription"].ToString();

                        specials.Add(special);
                    }
                }
            }

            return(specials);
        }
示例#2
0
        public void CanAddAndDeleteSpecials()
        {
            var          repo       = new VehicleRepositoryADO();
            SalesSpecial newSpecial = new SalesSpecial()
            {
                SpecialTitle       = "A New Special!",
                SpecialDescription = "This is only a test."
            };

            repo.AddSpecial(newSpecial);
            var specials = repo.GetSpecials();

            Assert.AreEqual(specials.Count(), 4);
            repo.DeleteSpecial(4);
            specials = repo.GetSpecials();
            Assert.AreEqual(specials.Count(), 3);
        }
        public void AddSpecial(SalesSpecial special)
        {
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("AddSpecial", cn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                SqlParameter param = new SqlParameter("@SpecialID", SqlDbType.Int);
                param.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(param);

                cmd.Parameters.AddWithValue("@SpecialTitle", special.SpecialTitle);
                cmd.Parameters.AddWithValue("@SpecialDescription", special.SpecialDescription);
                cn.Open();
                cmd.ExecuteNonQuery();
                special.SpecialID = (int)param.Value;
            }
        }