示例#1
0
        public IEnumerable <GetHomePage> GetHomePage()
        {
            List <GetHomePage> cars = new List <GetHomePage>();

            using (var conn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("GetAllFeatured", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                conn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        GetHomePage hp = new GetHomePage();

                        hp.CarId         = int.Parse(dr["CarId"].ToString());
                        hp.Year          = int.Parse(dr["Year"].ToString());
                        hp.MakeName      = dr["MakeName"].ToString();
                        hp.ModelName     = dr["ModelName"].ToString();
                        hp.SalePrice     = int.Parse(dr["SalePrice"].ToString());
                        hp.ImageFileName = dr["ImageFileName"].ToString();

                        cars.Add(hp);
                    }
                }
                conn.Close();
            }
            using (var conn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("GetAllSpecials", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                conn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        GetHomePage hp = new GetHomePage();

                        hp.SpecialId          = int.Parse(dr["SpecialId"].ToString());
                        hp.SpecialTitle       = dr["SpecialTitle"].ToString();
                        hp.SpecialDescription = dr["SpecialDescription"].ToString();

                        cars.Add(hp);
                    }
                }
                conn.Close();
            }
            return(cars);
        }
示例#2
0
        public IEnumerable <GetHomePage> GetHomePage()
        {
            List <GetHomePage> cars = new List <GetHomePage>();

            using (_ctx)
            {
                var featuredCars = _ctx.GetAllFeatured();

                foreach (var featured in featuredCars)
                {
                    if (featured.IsPurchased != true)
                    {
                        GetHomePage hp = new GetHomePage();

                        hp.CarId         = featured.CarId;
                        hp.Year          = featured.Year;
                        hp.MakeName      = featured.MakeName;
                        hp.ModelName     = featured.ModelName;
                        hp.SalePrice     = featured.SalePrice;
                        hp.ImageFileName = featured.ImageFileName;

                        cars.Add(hp);
                    }
                }

                var listOfSpecials = GetSpecials();
                foreach (var s in listOfSpecials)
                {
                    GetHomePage hp = new GetHomePage();

                    hp.SpecialId          = s.SpecialId;
                    hp.SpecialTitle       = s.SpecialTitle;
                    hp.SpecialDescription = s.SpecialDescription;

                    cars.Add(hp);
                }
            }
            return(cars);
        }
        public IEnumerable <GetHomePage> GetHomePage()
        {
            List <GetHomePage> cars = new List <GetHomePage>();

            if (car1.IsFeatured == true)
            {
                GetHomePage hp = new GetHomePage();

                hp.CarId         = car1.CarId;
                hp.Year          = car1.Year;
                hp.MakeName      = car1.MakeName;
                hp.ModelName     = car1.ModelName;
                hp.SalePrice     = car1.SalePrice;
                hp.ImageFileName = car1.ImageFileName;

                hp.SpecialId          = special1.SpecialId;
                hp.SpecialTitle       = special1.SpecialTitle;
                hp.SpecialDescription = special1.SpecialDescription;

                cars.Add(hp);
            }
            return(cars);
        }