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())); }
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())); }
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))); } }
private IEnumerable <dynamic> GetData() { var db = new NwEntities(); return(db.Products); }