コード例 #1
0
 public CarViewModel Post(CarViewModel car)
 {
     if (car != null && ModelState.IsValid)
     {
         var newCar = new Car {
             Name = car.Name, Price = car.Price, Sold = car.Sold
         };
         // db.Add(newCar);
         db.Cars.Add(newCar);
         db.SaveChanges();
         car.Id = newCar.Id;
     }
     return(car);
 }
コード例 #2
0
        public ActionResult Cars_Create([DataSourceRequest] DataSourceRequest request, CarViewModel car)
        {
            var results = new List <CarViewModel>();

            if (car != null && ModelState.IsValid)
            {
                var newCar = new Car {
                    Name = car.Name, Category = car.Category, Discontinued = car.Discontinued, InStock = car.InStock
                };
                db.Cars.Add(newCar);
                db.SaveChanges();
                car.Id = newCar.Id;
                results.Add(car);
            }

            return(Json(results.ToDataSourceResult(request, ModelState)));
        }