public ActionResult Add(ChoreDoerModel model) { using (var context = new RotatingChoresContext()) { var newDoer = context.ChoreDoers.Create(); newDoer.GroupId = User.Identity.GetGroupId(); model.UpdateDoer(newDoer); try { context.ChoreDoers.Add(newDoer); context.SaveChanges(); TempData["Message"] = "New group member added!"; } catch (Exception e) { TempData["FailureMessage"] = e.Message; return(View(model)); } } return(RedirectToAction("Index")); }
public ActionResult Edit(ChoreDoerModel doerModel) { using (var context = new RotatingChoresContext()) { var doer = doerModel.GetRepresentedDoer(context); if (doer != null) { var group = GetUserGroup(context); doerModel.AddChoresList(doer, group); ValidateChores(doerModel); if (ModelState.IsValid && IsGroupObject(doer.GroupId)) { doerModel.UpdateDoer(doer); context.SaveChanges(); TempData["Message"] = "Chore doer profile has been updated!"; return(RedirectToAction("Index")); } return(View(doerModel)); } return(DoerNotFound()); } }