Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public ActionResult Edit(int? id)
  2. {
  3. if (id == null)
  4. {
  5. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  6. }
  7. Product product = db.Product.Find(id);
  8. if (product == null)
  9. {
  10. return HttpNotFound();
  11. }
  12. return View(product);
  13. }
  14. [HttpPost]
  15. [ValidateAntiForgeryToken]
  16. public ActionResult Edit([Bind(Include = "Id,Name,Comment,Last_edited")] Product product)
  17. {
  18. if (ModelState.IsValid)
  19. {
  20. db.Entry(product).State = EntityState.Modified;
  21. db.SaveChanges();
  22. return RedirectToAction("Index");
  23. }
  24. return View(product);
  25. }
  26.  
  27. [HttpPost]
  28. [ValidateAntiForgeryToken]
  29. public ActionResult Edit([Bind(Include = "Id,Name,Comment")] Product product)
  30. {
  31. product.Last_Edited = DateTime.UtcNow;
  32. if (ModelState.IsValid)
  33. {
  34.  
  35. db.Entry(product).State = EntityState.Modified;
  36. db.SaveChanges();
  37. return RedirectToAction("Index");
  38. }
  39. return View(product);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement