public ActionResult Create(int id = -1) { if (id == -1) return HttpNotFound(); PostModels post = new PostModels(); ProductModels prod = db.Products.Find(id); if (prod == null) return HttpNotFound(); post.prodId = id; return View(post); }
public ActionResult Create(PostModels postmodels) { ProductModels prod = db.Products.Find(postmodels.prodId); if (prod == null) return HttpNotFound(); postmodels.postDate = DateTime.Now; if (ModelState.IsValid) { db.Posts.Add(postmodels); db.SaveChanges(); return RedirectToAction("Index"); } return RedirectToAction("../Product/Index"); // return View(postmodels); }
public ActionResult Edit(PostModels postmodels) { if (ModelState.IsValid) { db.Entry(postmodels).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(postmodels); }