Exemple #1
0
        public List<OCar> GetAllCars()
        {
            List<OCar> cars = new List<OCar>();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand("SELECT * FROM Car", conn);
                command.Connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    OCar newOCar = new OCar();
                    newOCar.Id = reader.GetInt32(0);
                    newOCar.Make = reader.GetString(1);
                    newOCar.Model = reader.GetString(2);
                    newOCar.Year = reader.GetString(3);
                    newOCar.ImageUrl = reader.GetString(4);
                    newOCar.Title = reader.GetString(5);
                    newOCar.Description = reader.GetString(6);
                    newOCar.Price = reader.GetDecimal(7);
                    cars.Add(newOCar);
                }
            }

            return cars;
        }
Exemple #2
0
        public ActionResult Add(OCar oCar)
        {
            if (ModelState.IsValid)
            {
                _repo.AddCar(oCar);
                var cars = _repo.GetAllCars();
                return View("Index", cars);

            }
            else
            {
                return View();
            }
        }
Exemple #3
0
        public void TestAddToRepo()
        {
            OCar c = new OCar()
            {
                Description = "Spam",
                Title = "Spam",
                Year = "1987",
                Make = "Nissan",
                Model = "Stanza",
                Price = 9999.00M,
                ImageUrl = "http://carphotos.cardomain.com/ride_images/1/1287/3601/3216800003_large.jpg"
            };

            var _repo = new MockCarRepository();
            _repo.AddCar(c);
        }
Exemple #4
0
        public void AddCar(OCar oCar)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                var commandText = "INSERT INTO Car (Make, Model, Year, ImageUrl, Title, Description, Price) VALUES (@Make, @Model, @Year, @ImageUrl, @Title, @Description, @Price)";
                SqlCommand command = new SqlCommand(commandText, conn);
                command.Parameters.AddWithValue("@Make", oCar.Make);
                command.Parameters.AddWithValue("@Model", oCar.Model);
                command.Parameters.AddWithValue("@Year", oCar.Year);
                command.Parameters.AddWithValue("@ImageUrl", oCar.ImageUrl);
                command.Parameters.AddWithValue("@Description", oCar.Description);
                command.Parameters.AddWithValue("@Title", oCar.Title);
                command.Parameters.AddWithValue("@Price", oCar.Price);

                command.Connection.Open();
                command.ExecuteNonQuery();
            }
        }
Exemple #5
0
        public void EditCar(OCar oCar)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                var commandText = "UPDATE Car SET Make = @Make, Model = @Model, Year = @Year, ImageUrl = @ImageUrl, Title = @Title, Description = @Description, Price = @Price WHERE Id = @Id";
                SqlCommand command = new SqlCommand(commandText, conn);
                command.Parameters.AddWithValue("@Id", oCar.Id);
                command.Parameters.AddWithValue("@Make", oCar.Make);
                command.Parameters.AddWithValue("@Model", oCar.Model);
                command.Parameters.AddWithValue("@Year", oCar.Year);
                command.Parameters.AddWithValue("@ImageUrl", oCar.ImageUrl);
                command.Parameters.AddWithValue("@Description", oCar.Description);
                command.Parameters.AddWithValue("@Title", oCar.Title);
                command.Parameters.AddWithValue("@Price", oCar.Price);

                command.Connection.Open();
                command.ExecuteNonQuery();
            }
        }
Exemple #6
0
        public void AddCar(OCar oCar)
        {
            //car.Id = Cars.Max(c => c.Id) + 1;
            using (CarDBEntities2 cars = new CarDBEntities2())
            {
                cars.Cars.Add(new Car()
                {
                    Model = oCar.Model,
                    Make = oCar.Make,
                    Description = oCar.Description,
                    ImageUrl = oCar.ImageUrl,
                    Price = oCar.Price,
                    Title = oCar.Title,
                    Year = oCar.Year
                });

                cars.SaveChanges();

            }
        }
Exemple #7
0
        public void TestEditRepo()
        {
            var _repo = new MockCarRepository();
            var car = _repo.GetAllCars().FirstOrDefault(x => x.Make == "Nissan" && x.Model == "Stanza" && x.Year == "1987");

            if (car != null)
            {
                OCar c = new OCar()
                {
                    Id = car.Id,
                    Description = "Well, well, well, what do we have here? A car with four doors? Check. A car with a solid roof? Check. A car with rearview mirrors so you can really connect with that Pearl Jam song? Psh, DOUBLE CHECK. We here at SWCG understand that your discriminating tastes demand that you're able to stand up to authority in style, and this 1987 Nissan Stanza virtually screams: \"Live free or die!\". Rest assured, the seat belts will help ensure that you can live free AND live. That's the SWCG guarentee. You're welcome. ",
                    Title = "PATRIOTIC Nissan Stanza from the year of our Lord 1987",
                    Year = "1987",
                    Make = "Nissan",
                    Model = "Stanza",
                    Price = 9999.00M,
                    ImageUrl = "http://carphotos.cardomain.com/ride_images/1/1287/3601/3216800003_large.jpg"
                };

                _repo.EditCar(c);
            }
        }
Exemple #8
0
        public OCar GetCarByModel(string name)
        {
            OCar newOCar = new OCar();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand("SELECT * FROM Car WHERE Model = '" + name + "'", conn);
                command.Connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    newOCar = new OCar();
                    newOCar.Id = reader.GetInt32(0);
                    newOCar.Make = reader.GetString(1);
                    newOCar.Model = reader.GetString(2);
                    newOCar.Year = reader.GetString(3);
                    newOCar.ImageUrl = reader.GetString(4);
                    newOCar.Title = reader.GetString(5);
                    newOCar.Description = reader.GetString(6);
                    newOCar.Price = reader.GetDecimal(7);
                }
            }
            return newOCar;
        }
Exemple #9
0
 public void EditCar(OCar oCar)
 {
 }
Exemple #10
0
 public void EditCar(OCar oCar)
 {
     this.DeleteCar(oCar.Id);
     Cars.Add(oCar);
 }
Exemple #11
0
 public void AddCar(OCar oCar)
 {
     oCar.Id = Cars.Max(c => c.Id) + 1;
     Cars.Add(oCar);
 }