public ActionResult Edit(int id) { var service = CreateDoulaService(); var detail = service.GetDoulaById(id); var model = new DoulaEdit { DoulaId = detail.DoulaId, DoulaLocation = detail.DoulaLocation, AvailJan = detail.AvailJan, AvailFeb = detail.AvailFeb, AvailMar = detail.AvailMar, AvailApr = detail.AvailApr, AvailMay = detail.AvailMay, AvailJun = detail.AvailJun, AvailJul = detail.AvailJul, AvailAug = detail.AvailAug, AvailSep = detail.AvailSep, AvailOct = detail.AvailOct, AvailNov = detail.AvailNov, AvailDec = detail.AvailDec }; return(View(model)); }
public bool UpdateDoula(DoulaEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Doulas .Single(e => e.DoulaId == model.DoulaId && e.OwnerId == _userId); entity.DoulaId = model.DoulaId; entity.DoulaName = model.DoulaName; entity.DoulaLocation = model.DoulaLocation; entity.AvailJan = model.AvailJan; entity.AvailFeb = model.AvailFeb; entity.AvailMar = model.AvailMar; entity.AvailApr = model.AvailApr; entity.AvailMay = model.AvailMay; entity.AvailJun = model.AvailJun; entity.AvailJul = model.AvailJul; entity.AvailAug = model.AvailAug; entity.AvailSep = model.AvailSep; entity.AvailOct = model.AvailOct; entity.AvailNov = model.AvailNov; entity.AvailDec = model.AvailDec; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, DoulaEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.DoulaId != id) { ModelState.AddModelError("", "ID MisMatch"); return(View(model)); } var service = CreateDoulaService(); if (service.UpdateDoula(model)) { TempData["SaveResult"] = "The profile has been updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The profile could not be updated."); return(View(model)); }