public ActionResult Edit(int id, ConvictionEdit model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateConvictionService(); if (service.UpdateConviction(id, model)) { TempData["SaveResult"] = "Conviction Updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Conviction not Updated"); return(View(model)); }
// Conviction/Edit/{id} public ActionResult Edit(int id) { var service = CreateConvictionService(); var detail = service.GetConvictionById(id); var model = new ConvictionEdit { ConvicID = detail.ConvicID, StreetAddress = detail.StreetAddress, City = detail.City, County = detail.County, State = detail.State, Zipcode = detail.Zipcode, DateOfConviction = DateTime.Now, ConvictionSeverity = detail.ConvictionSeverity, ArrestID = detail.ArrestID, DefendantID = detail.DefendantID, CourtHearingID = detail.CourtHearingID }; return(View(model)); }
public bool UpdateConviction(int id, ConvictionEdit model) { using (var con = new ApplicationDbContext()) { var entity = con .Convictions .Single(e => e.ConvicID == id); entity.StreetAddress = model.StreetAddress; entity.City = model.City; entity.County = model.County; entity.State = model.State; entity.Zipcode = model.Zipcode; entity.DateOfConviction = model.DateOfConviction; entity.ConvictionSeverity = model.ConvictionSeverity; entity.ArrestID = model.ArrestID; entity.DefendantID = model.DefendantID; entity.CourtHearingID = model.CourtHearingID; return(con.SaveChanges() == 1); } }