public ActionResult CreateProduct([DataSourceRequest] DataSourceRequest request, ProductViewModel product, string productCategoryId) { var categoryId = Int32.Parse(productCategoryId); if (product != null && ModelState.IsValid) { var newProduct = new Product() { ProductName = product.viewProductName, ProductCategoryId = categoryId, ProductPrice = product.viewProductPrice, ProductQuantity = product.viewProductQuantity, ProductValidFrom = product.viewProductValidFrom }; db.Products.Add(newProduct); db.SaveChanges(); product.viewProductId = newProduct.ProductId; } return Json(new[] { product }.ToDataSourceResult(request, ModelState)); }
public ActionResult UpdateProduct([DataSourceRequest] DataSourceRequest request, ProductViewModel product) { if (product != null && ModelState.IsValid) { var newProduct = new Product() { ProductId = product.viewProductId, ProductName = product.viewProductName, ProductCategoryId = product.viewProductCategoryId, ProductPrice = product.viewProductPrice, ProductQuantity = product.viewProductQuantity, ProductValidFrom = product.viewProductValidFrom }; db.Products.Attach(newProduct); db.Entry(newProduct).State = EntityState.Modified; db.SaveChanges(); } return Json(new[] { product }.ToDataSourceResult(request, ModelState)); }
public ActionResult DestroyProduct([DataSourceRequest] DataSourceRequest request, ProductViewModel product) { if (product != null) { var newProduct = new Product() { ProductId = product.viewProductId }; db.Products.Attach(newProduct); db.Products.Remove(newProduct); db.SaveChanges(); } return Json(new[] { product }.ToDataSourceResult(request, ModelState)); }