public ActionResult Edit(int id, ConventionEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ConventionId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateConventionService(); if (service.UpdateConvention(model)) { TempData["SaveResult"] = "The convention was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The convention could not be updated."); return(View(model)); }
public ActionResult Edit(int id) { var service = CreateConventionService(); var detail = service.GetConventionById(id); var model = new ConventionEdit { ConventionId = detail.ConventionId, Name = detail.Name, City = detail.City, State = detail.State, StartDate = detail.StartDate, EndDate = detail.EndDate, Hotel = detail.Hotel }; return(View(model)); }
public bool UpdateConvention(ConventionEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Conventions .Single(e => e.ConventionId == model.ConventionId); entity.ConventionId = model.ConventionId; entity.Name = model.Name; entity.City = model.City; entity.State = model.State; entity.StartDate = model.StartDate; entity.EndDate = model.EndDate; entity.Hotel = model.Hotel; entity.Website = model.Website; return(ctx.SaveChanges() == 1); } }