public ActionResult Edit(int id, SleepEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SleepId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateSleepService(); if (service.UpdateSleep(model)) { TempData["SaveResult"] = "Your entry was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your entry could not be updated."); ViewBag.PersonId = new SelectList(_db.Persons, "PersonId", "Name", model.PersonId); return(View(model)); }
// GET : Sleep Data public ActionResult Edit(int id) { var service = CreateSleepService(); var babyService = CreateBabyService(); var detail = service.GetSleepById(id); var babies = babyService.GetBaby() .Select(x => new { Text = x.Name, Value = x.BabyID }); var model = new SleepEdit { BabyID = detail.BabyID, SleepID = detail.SleepID, Location = detail.Location, SleepStart = detail.SleepStart, SleepEnd = detail.SleepEnd, Notes = detail.Notes, Babies = new SelectList(babies, "Value", "Text") }; return(View(model)); }
public bool UpdateSleep(SleepEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Sleeps .Single(e => e.SleepId == model.SleepId && e.OwnerId == _userId); entity.HoursSlept = model.HoursSlept; entity.WakeUpTime = model.WakeUpTime; entity.Date = model.Date; entity.PersonId = model.PersonId; return(ctx.SaveChanges() == 1); } }
public bool UpdateSleep(SleepEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Sleeps .Single(e => e.ID == model.SleepID && e.ParentID == _userID); entity.Location = model.Location; entity.SleepStart = model.SleepStart; entity.SleepEnd = model.SleepEnd; entity.Notes = model.Notes; entity.BabyID = model.BabyID; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateSleepService(); var detail = service.GetSleepById(id); var model = new SleepEdit { SleepId = detail.SleepId, HoursSlept = detail.HoursSlept, WakeUpTime = detail.WakeUpTime, Date = detail.Date, PersonId = detail.PersonId }; ViewBag.PersonId = new SelectList(_db.Persons, "PersonId", "Name", model.PersonId); return(View(model)); }
public ActionResult Edit(int id, SleepEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SleepID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateSleepService(); if (service.UpdateSleep(model)) { TempData["SaveResult"] = "The sleep data was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The sleep data could not be updated."); return(View()); }