public ActionResult Edit(int id, ConnectionEditModel model) { //Defensive coding if (model.ConnectionID != id) { ModelState.AddModelError("", "Nice try!"); model.ConnectionID = id; return(View(model)); } if (!ModelState.IsValid) { return(View(model)); } if (!CreateConnectionService().UpdateEvent(model)) { ModelState.AddModelError("", "Unable to update connection"); return(View(model)); } TempData["SaveResult"] = "Your connection was saved"; return(RedirectToAction("Index")); }
public IHttpActionResult Put(ConnectionEditModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateConnectionService(); if (!service.UpdateConnection(model)) { return(InternalServerError()); } return(Ok()); }
// GET: Connection/Edit/5 public ActionResult Edit(int id) { var service = CreateConnectionService(); var detail = service.GetConnectionById(id); var model = new ConnectionEditModel { ConnectionID = detail.ConnectionID, ConnectionName = detail.ConnectionName, Job = detail.Job, Employer = detail.Employer, Phone = detail.Phone, Email = detail.Phone, Notes = detail.Notes }; return(View(model)); }
public bool UpdateConnection(ConnectionEditModel model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Connections .Single(e => e.ConnectionID == model.ConnectionID && e.UserID == _userId); entity.ConnectionName = model.ConnectionName; entity.Job = model.Job; entity.Employer = model.Employer; entity.Phone = model.Phone; entity.Email = model.Email; entity.Notes = model.Notes; entity.EventID = model.EventID; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, ConnectionEditModel model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ConnectionID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateConnectionService(); if (service.UpdateConnection(model)) { TempData["SaveResult"] = "Your connection was updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your connection could not be updated."); return(View(model)); }