예제 #1
0
 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));
 }
예제 #2
0
 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));
 }
예제 #3
0
 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));
 }