Ejemplo n.º 1
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)));
        }
Ejemplo n.º 2
0
 public ActionResult Cars_Update([DataSourceRequest] DataSourceRequest request, CarViewModel car)
 {
     if (car != null && ModelState.IsValid)
     {
         var dbCar = db.Cars.Where(c => c.Id == car.Id).SingleOrDefault();
         if (dbCar != null)
         {
             dbCar.Name     = car.Name;
             dbCar.Category = car.Category; dbCar.Discontinued = car.Discontinued;
             dbCar.InStock  = car.InStock;
         }
     }
     db.SaveChanges();
     return(Json(new[] { car }.ToDataSourceResult(request, ModelState)));
 }
Ejemplo n.º 3
0
        public ActionResult Cars_Destroy([DataSourceRequest] DataSourceRequest request, CarViewModel car)
        {
            var dbCar = db.Cars.Where(c => c.Id == car.Id).SingleOrDefault();

            db.Cars.Remove(dbCar);
            db.SaveChanges();
            return(Json(new[] { car }.ToDataSourceResult(request)));
        }