public IEnumerable <FeaturedVehicle> GetFeatured()
        {
            List <FeaturedVehicle> featured = new List <FeaturedVehicle>();

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

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var vehicle = new FeaturedVehicle();
                        vehicle.ID            = (int)dr["ID"];
                        vehicle.Make          = dr["Make"].ToString();
                        vehicle.Model         = dr["Model"].ToString();
                        vehicle.Year          = (int)dr["Year"];
                        vehicle.SalePrice     = (decimal)dr["SalePrice"];
                        vehicle.ImageFileName = dr["ImageFileName"].ToString();

                        featured.Add(vehicle);
                    }
                }
            }

            return(featured);
        }
Beispiel #2
0
        public List <FeaturedVehicle> GetFeaturedVehicles()
        {
            List <FeaturedVehicle> vehicles = new List <FeaturedVehicle>();

            using (var cn = new SqlConnection("Server=localhost;Database=GuildCars;User Id=sa;Password=sqlserver;"))
            {
                SqlCommand cmd = new SqlCommand("DisplayFeaturedVehicles", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        FeaturedVehicle currentRow = new FeaturedVehicle();

                        currentRow.ImageFileName = dr["ImageFilePath"].ToString();
                        currentRow.MakeName      = dr["MakeName"].ToString();
                        currentRow.ModelName     = dr["ModelName"].ToString();
                        currentRow.VehicleId     = (int)dr["VehicleId"];
                        currentRow.Year          = dr["ModelYear"].ToString();
                        currentRow.Price         = (int)dr["Price"];

                        vehicles.Add(currentRow);
                    }
                }
            }

            return(vehicles);
        }
Beispiel #3
0
        public void AddFeatured(int vehicleId)
        {
            var feature = new FeaturedVehicle();

            feature.FeaturedId = GetNextFeatureId();
            feature.VehicleId  = vehicleId;
            _features.Add(feature);
        }