// GET : Nursing Data public ActionResult Edit(int id) { var service = CreateNursingService(); var babyService = CreateBabyService(); var detail = service.GetNursingDataById(id); var babies = babyService.GetBaby() .Select(x => new { Text = x.Name, Value = x.BabyID }); var model = new NursingEdit { NursingID = detail.NursingID, Time = detail.Time, TimeFed = detail.TimeFed, Name = detail.Name, FeedingSide = detail.FeedingSide, Notes = detail.Notes, Babies = new SelectList(babies, "Value", "Text"), BabyID = detail.BabyID }; return(View(model)); }
public bool UpdateNursingData(NursingEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Nursings .Single(e => e.ID == model.NursingID && e.ParentID == _userID); entity.Time = model.Time; entity.TimeFed = model.TimeFed; entity.Name = model.Name; entity.FeedingSide = model.FeedingSide; entity.Notes = model.Notes; entity.BabyID = model.BabyID; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, NursingEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.NursingID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateNursingService(); if (service.UpdateNursingData(model)) { TempData["SaveResult"] = "The nursing data was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The nursing data could not be updated."); return(View()); }