// GET : Baby Details by ID public ActionResult Edit(int id) { var service = CreateBabyService(); var detail = service.GetBabyById(id); var model = new BabyEdit { BabyID = detail.BabyID, Name = detail.Name, BirthDate = detail.BirthDate, Gender = detail.Gender, Notes = detail.Notes }; return(View(model)); }
public ActionResult Edit(int id, BabyEdit model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateBabyService(); if (service.UpdateBaby(model)) { TempData["SaveResult"] = "The baby was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The baby could not be updated."); return(View()); }
public bool UpdateBaby(BabyEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Babies .Single(e => e.ID == model.BabyID && e.ParentID == _userID); entity.Name = model.Name; entity.Gender = model.Gender; entity.Notes = model.Notes; entity.BirthDate = model.BirthDate; entity.ID = model.BabyID; return(ctx.SaveChanges() == 1); } }