public ActionResult AddNew(OrgInfo OrgInfo) { if (ModelState.IsValid) { var insertOperation = TableOperation.Insert(OrgInfo); try { OrgInfoTable.Execute(insertOperation); } catch (StorageException se) { ViewBag.errorMessage = "HomeID already taken, try another name."; Trace.TraceError(se.Message); return View("Error"); } return RedirectToAction("Index"); } return View(OrgInfo); }
public ActionResult Edit(string partitionKey, string rowKey, OrgInfo editedOrgInfo) { if (ModelState.IsValid) { var OrgInfo = new OrgInfo(); UpdateModel(OrgInfo); try { var replaceOperation = TableOperation.Replace(OrgInfo); OrgInfoTable.Execute(replaceOperation); return RedirectToAction("Index"); } catch (StorageException ex) { if (ex.RequestInformation.HttpStatusCode == 412) { // Concurrency error var currentOrgInfo = FindRow(partitionKey, rowKey); if (currentOrgInfo.OrgID != editedOrgInfo.OrgID) { ModelState.AddModelError("OrgID", "Current value: " + currentOrgInfo.OrgID); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); ModelState.SetModelValue("ETag", new ValueProviderResult(currentOrgInfo.ETag, currentOrgInfo.ETag, null)); } else { throw; } } } return View(editedOrgInfo); }