示例#1
0
        public IEnumerable <SpecialAd> GetAllSpecials()
        {
            List <SpecialAd> ads = new List <SpecialAd>();


            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString =
                    Settings.GetConnectionString();

                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.CommandText = "RetreiveAds";

                conn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        SpecialAd ad = new SpecialAd();
                        ad.SpecialAdId = (int)dr["SpecialAdId"];
                        ad.Title       = dr["Title"].ToString();
                        ad.Description = dr["Description"].ToString();
                        ads.Add(ad);
                    }
                }
            }

            return(ads);
        }
示例#2
0
        public void RemoveSpecial(int id)
        {
            SpecialAd item = GetSpecialById(id);

            if (item != null)
            {
                Specials.Remove(item);
                (this).SaveChanges();
            }
        }
        public void AddSpecialRuleTest(string title, string description)
        {
            var repo = CarDearlershipRespoFacotory.GetRepository();

            SpecialAd newSpecialAd = repo.AddSpecial(title, description);

            Assert.NotNull(newSpecialAd);
            Assert.AreEqual(title, newSpecialAd.Title);
            Assert.AreEqual(description, newSpecialAd.Description);
        }
示例#4
0
        public SpecialAd AddSpecial(string title, string description)
        {
            SpecialAd special = new SpecialAd();

            special.SpecialAdId = Specials.Max(i => i.SpecialAdId) + 1;
            special.Title       = title;
            special.Description = description;

            Specials.Add(special);
            (this).SaveChanges();
            return(special);
        }