コード例 #1
0
 //mapper to convert from viewmodel to domain model 
 public static Models.Car MapCarAddEditToCar(CarAddEdit caraddedit)
 {
     var car = new Models.Car();
     car.CarId = caraddedit.CarId;
     car.Make = caraddedit.Make;
     car.Model = caraddedit.Model;
     return car;
 }
コード例 #2
0
 //mapper to convert from domain model to viewmodel - would be easier with Automapper 
 public static CarAddEdit MapCarToCarAddEdit(Models.Car car)
 {
     var caraddedit = new CarAddEdit();
     caraddedit.CarId = car.CarId;
     caraddedit.Make = car.Make;
     caraddedit.Model = car.Model;
     return caraddedit;
 }
コード例 #3
0
        //mapper to convert from viewmodel to domain model
        public static Models.Car MapCarAddEditToCar(CarAddEdit caraddedit)
        {
            var car = new Models.Car();

            car.CarId = caraddedit.CarId;
            car.Make  = caraddedit.Make;
            car.Model = caraddedit.Model;
            return(car);
        }
コード例 #4
0
        //mapper to convert from domain model to viewmodel
        public static CarAddEdit MapCarToCarAddEdit(Models.Car car)
        {
            var caraddedit = new CarAddEdit();

            caraddedit.CarId = car.CarId;
            caraddedit.Make  = car.Make;
            caraddedit.Model = car.Model;
            return(caraddedit);
        }
コード例 #5
0
        public ActionResult Edit(CarAddEdit viewmodel)
        {
            if (ModelState.IsValid)
            {
                using (_connection = Utilities.GetOpenConnection())
                {
                    _connection.Update(CarAddEdit.MapCarAddEditToCar(viewmodel));
                }
                return RedirectToAction("index");
            }

            return View(viewmodel);
        }
コード例 #6
0
 public ActionResult Create(CarAddEdit viewmodel)
 {
     if (ModelState.IsValid)
     {
         //manual mapping - this would be easier with automapper
         var car = CarAddEdit.MapCarAddEditToCar(viewmodel);
         using (_connection = Utilities.GetOpenConnection())
         {
             _connection.Insert(car);
         }
         return RedirectToAction("index");
     }
     return View(viewmodel);
 }