コード例 #1
0
        public ActionResult CreateCar(Vehicle car)
        {
            var manager = new VehicleManager();
            var response = manager.AddCar(car);

            return View("Home");
        }
コード例 #2
0
        public void AddCar(Vehicle newCar)
        {
            using (var context = new DealershipContext())
            {

                context.Vehicles.Add(newCar);
                context.SaveChanges();
            }
        }
コード例 #3
0
        public Vehicle GetVehicleByID(int id)
        {
            var result = new Vehicle();
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var p = new DynamicParameters();
                p.Add("VehicleID", id);
                result = cn.Query<Vehicle>("SELECT * FROM Vehicle WHERE VehicleID = @VehicleID ", p).FirstOrDefault();
            }

            return result;
        }
コード例 #4
0
        public Response<Vehicle> AddCar(Vehicle newCar)
        {
            var response = new Response<Vehicle>();

            try
            {
                response.Success = true;
                response.Message = "A new car was added";
                 _repo.AddCar(newCar);

            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
コード例 #5
0
        public void AddVehicle(Vehicle vehicle)
        {
            int available = Convert.ToInt32(vehicle.IsAvailable);

            using (var connect = new SqlConnection(Settings.ConnectionString))
            {
                var command = new SqlCommand("INSERT INTO Vehicle " +
                                             "(AdTitle, Description, Make, Milage, IsAvailable, Price, UrlPicture, Year) " +
                                             "VALUES (@AdTitle, @Description, @Make, @Milage, @IsAvailable, @Price, @UrlPicture, @Year)", connect);
                command.Parameters.Add(new SqlParameter("AdTitle", vehicle.AdTitle));
                command.Parameters.Add(new SqlParameter("Description", vehicle.Description));
                command.Parameters.Add(new SqlParameter("Make", vehicle.Make));
                command.Parameters.Add(new SqlParameter("Milage", vehicle.Mileage));
                command.Parameters.Add(new SqlParameter("IsAvailable", available));
                command.Parameters.Add(new SqlParameter("Price", vehicle.Price));
                command.Parameters.Add(new SqlParameter("UrlPicture", vehicle.UrlPicture));
                command.Parameters.Add(new SqlParameter("Year", vehicle.Year.Date));

                connect.Open();

                command.ExecuteNonQuery();
            }
        }
コード例 #6
0
 public HttpResponseMessage PostAddVehicle(Vehicle v)
 {
     return null;
 }
コード例 #7
0
 public ActionResult ViewPartial(Vehicle data)
 {
     return View("_ViewMore", data);
 }
コード例 #8
0
 public ActionResult AddCar(Vehicle c)
 {
     return View();
 }