Beispiel #1
0
 public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, int productId)
 {
     using (var db = new NwEntities())
     {
         db.Products.DeleteObject(db.Products.First(p => p.ProductID == productId));
         db.SaveChanges();
     }
     return(Json(ModelState.ToDataSourceResult()));
 }
Beispiel #2
0
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, int productId)
        {
            using (var db = new NwEntities())
            {
                var productToUpdate = db.Products.First(p => p.ProductID == productId);

                if (TryUpdateModel(productToUpdate, includeProperties: new string[] { "ProductName", "UnitPrice", "QuantityPerUnit" }))
                {
                    db.SaveChanges();
                }
            }
            return(Json(ModelState.ToDataSourceResult()));
        }
Beispiel #3
0
 public ActionResult Create([DataSourceRequest] DataSourceRequest request)
 {
     using (var db = new NwEntities())
     {
         var product = new Product();
         if (TryUpdateModel(product, includeProperties: new string[] { "ProductName", "UnitPrice", "QuantityPerUnit" }))
         {
             db.Products.AddObject(product);
             db.SaveChanges();
         }
         return(Json(new [] { product }.ToDataSourceResult(request)));
     }
 }
Beispiel #4
0
        private IEnumerable <dynamic> GetData()
        {
            var db = new NwEntities();

            return(db.Products);
        }