// CREATE CHOREUSER WITH CHOREID public ActionResult CreateChoreUserWithChoreId(int id) { var service = CreateChoreUserService(); var detail = service.GetChoreById(id); var model = new ChoreUserCreate { ChoreId = (int)detail.ChoreId }; return(View(model)); }
// CREATE public bool Create(ChoreUserCreate model) { var entity = new ChoreUser() { UserId = _userId.ToString(), ChoreId = model.ChoreId, }; using (var ctx = new ApplicationDbContext()) { ctx.ChoreUsers.Add(entity); return(ctx.SaveChanges() == 1); } }
// CREATE CHOREUSER WITH CHOREID public bool CreateChoreUser(ChoreUserCreate model) { using (var ctx = new ApplicationDbContext()) { var chore = GetChoreById(model.ChoreId); var entity = new ChoreUser() { UserId = _userId.ToString(), ChoreId = model.ChoreId, ChoreIsComplete = model.ChoreIsComplete }; ctx.ChoreUsers.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ChoreUserCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateChoreUserService(); if (service.CreateChoreUser(model)) { TempData["SaveResult"] = "Chore User was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Chore User could not be created."); return(View(model)); }