// remove user from a sepecific wedding public IActionResult UnRsvp(int id) { WedPlan connection = _context.weddingplan.SingleOrDefault(wp => wp.id == id); if (connection != null) { _context.Remove(connection); _context.SaveChanges(); } return(RedirectToAction("AllWeddings")); }
// add loged user to a selected wedding public IActionResult Rsvp(int id) { int?userId = HttpContext.Session.GetInt32("userId"); // find user by user id Users userLog = _context.users.SingleOrDefault(user => user.id == userId); Wedd weddLog = _context.weddings.SingleOrDefault(wed => wed.id == id); WedPlan wedPlan = new WedPlan() { wedding = weddLog, user = userLog }; // userLog.wedPlan. _context.Add(wedPlan); _context.SaveChanges(); return(RedirectToAction("AllWeddings")); }