public CustomerEditContactInfo ( |
||
newItem | ||
return |
public ActionResult Edit(int?id, CustomerEditContactInfo newItem) { // Validate the input if (!ModelState.IsValid) { // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.CustomerId })); } if (id.GetValueOrDefault() != newItem.CustomerId) { // This appears to be data tampering, so redirect the user away return(RedirectToAction("index")); } // Attempt to do the update var editedItem = m.CustomerEditContactInfo(newItem); if (editedItem == null) { // There was a problem updating the object // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.CustomerId })); } else { // Show the details view, which will have the updated data return(RedirectToAction("details", new { id = newItem.CustomerId })); } }
public ActionResult Edit(int?id, CustomerEditContactInfo newItem) { // Validate the input if (!ModelState.IsValid) { // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.CustomerId })); } if (id.GetValueOrDefault() != newItem.CustomerId) { // This appears to be data tampering, so redirect the user away return(RedirectToAction("index")); } // Attention 03 (web app) - Error - cause a validation error when saving to the store // At this point in the method, newItem has passed the initial validation test // Set a breakpoint at line 139 below // So, let's invalidate some of its values (null or string too long), // and pass it to the manager, which will attempt to save it to the data store // Then, BOOM!, a DbEntity validation error will appear // Set a required value to null newItem.Email = null; // Set another to a too-long value newItem.Phone = "This string is too long. It exceeds the 24-character limit."; // Attempt to do the update var editedItem = m.CustomerEditContactInfo(newItem); if (editedItem == null) { // There was a problem updating the object // Our "version 1" approach is to display the "edit form" again return(RedirectToAction("edit", new { id = newItem.CustomerId })); } else { // Show the details view, which will have the updated data return(RedirectToAction("details", new { id = newItem.CustomerId })); } }
public ActionResult Edit(int?id, CustomerEditContactInfo newItem) { if (!ModelState.IsValid) { return(RedirectToAction("edit", new { id = newItem.CustomerId })); } if (id.GetValueOrDefault() != newItem.CustomerId) { return(RedirectToAction("index")); } var editedItem = m.CustomerEditContactInfo(newItem); if (editedItem == null) { return(RedirectToAction("edit", new { id = newItem.CustomerId })); } else { return(RedirectToAction("details", new { id = newItem.CustomerId })); } }