// // GET: /Product/Create public ActionResult Create(int id) { CategoryRepo cr = new CategoryRepo(); if (cr.ValidateID(id)) { ProductModel p = new ProductModel(); p.Category = id; return View(p); } return RedirectToAction("Index", "Category"); }
public void EditProduct(int id, ProductModel product) { var pr = context.ProductModels.Single(p => p.ID == id); pr.Name = product.Name; pr.Description = product.Description; pr.Count = product.Count; pr.Price = product.Price; context.SubmitChanges(); }
public ActionResult Create(int id, ProductModel product) { try { product.Category = id; if (ModelState.IsValid) { products.AddProduct(product); if(Request.IsAjaxRequest()) return Json(new { success = true }); return RedirectToAction("Index", "Category", new { id=id }); } if (Request.IsAjaxRequest()) return Json(new { success = false, errors = ModelState.Values.SelectMany(v => v.Errors) }); return View(product); } catch (Exception e) { if (Request.IsAjaxRequest()) return Json(new { success = false, error = e.Message }); return View(); } }
public void AddProduct(ProductModel product) { context.ProductModels.InsertOnSubmit(product); context.SubmitChanges(); }
public ActionResult Edit(int id, ProductModel product) { try { if (ModelState.IsValid) { products.EditProduct(id, product); if (Request.IsAjaxRequest()) return Json(new { success = true }); return RedirectToAction("Details", "Product", new { id=id }); } if (Request.IsAjaxRequest()) return Json(new { success = false, errors = ModelState.Values.SelectMany(v => v.Errors) }); product.ID = id; return View(product); } catch(Exception e) { if (Request.IsAjaxRequest()) return Json(new { success = false, error = e.Message }); return View(); } }
partial void DeleteProductModel(ProductModel instance);
partial void UpdateProductModel(ProductModel instance);
partial void InsertProductModel(ProductModel instance);
private void detach_ProductModels(ProductModel entity) { this.SendPropertyChanging(); entity.CategoryModel = null; }