public ActionResult Edit(int id) { var service = CreateIntFamilyService(); var detail = service.GetIntFamilyById(id); var model = new IntFamilyEdit { IntFamId = detail.IntFamId, Parent1Name = detail.Parent1Name, Parent2Name = detail.Parent2Name, Country = detail.Country }; return(View(model)); }
public bool UpdateIntFamily(IntFamilyEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .IntFamilies .Single(e => e.IntFamId == model.IntFamId && e.OwnerId == _userId); entity.Parent1Name = model.Parent1Name; entity.Parent2Name = model.Parent2Name; entity.PhoneNumber = model.PhoneNumber; entity.Email = model.Email; entity.Country = model.Country; entity.USCISExpiration = model.USCISExpiration; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, IntFamilyEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.IntFamId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateIntFamilyService(); if (service.UpdateIntFamily(model)) { TempData["SaveResult"] = "Your family was updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your family could not be updated"); return(View(model)); }