public IActionResult RSVP(int WeddingId) { if (HttpContext.Session.GetInt32("Uuid") == null) { return(Redirect("/")); } int Uuid = (int)HttpContext.Session.GetInt32("Uuid"); //check for security if (_context.UserWeddingRSVPs.Any(r => r.UserRSVPedId == Uuid && r.WeddingRSVPedId == WeddingId)) { return(RedirectToAction("Dashboard")); } UserWeddingRSVP ToAdd = new UserWeddingRSVP() { UserRSVPedId = Uuid, WeddingRSVPedId = WeddingId }; _context.Add(ToAdd); _context.SaveChanges(); return(RedirectToAction("Dashboard")); }
public IActionResult RSVP(int weddingId) { if (!isLoggedIn) { return(RedirectToAction("Index", "Home")); } UserWeddingRSVP existingRSVP = db.UserWeddingRSVPs .FirstOrDefault(rsvp => rsvp.UserId == uid && rsvp.WeddingId == weddingId); if (existingRSVP == null) { UserWeddingRSVP rsvp = new UserWeddingRSVP() { WeddingId = weddingId, UserId = (int)uid }; db.UserWeddingRSVPs.Add(rsvp); } else { db.UserWeddingRSVPs.Remove(existingRSVP); } db.SaveChanges(); return(RedirectToAction("Dashboard")); }
public IActionResult UnRSVP(int WeddingId) { if (HttpContext.Session.GetInt32("Uuid") == null) { return(Redirect("/")); } int Uuid = (int)HttpContext.Session.GetInt32("Uuid"); //check for security if (!_context.UserWeddingRSVPs.Any(r => r.UserRSVPedId == Uuid && r.WeddingRSVPedId == WeddingId)) { return(RedirectToAction("Dashboard")); } UserWeddingRSVP ToRemove = _context.UserWeddingRSVPs.FirstOrDefault(r => r.UserRSVPedId == Uuid && r.WeddingRSVPedId == WeddingId); _context.Remove(ToRemove); _context.SaveChanges(); return(RedirectToAction("Dashboard")); }
public IActionResult RSVP(int weddingid) { // is the user RSVP'd in the wedding coming in? UserWeddingRSVP existingRSVP = db.UserWeddingRSVPs .FirstOrDefault(rsvp => rsvp.UserId == (int)HttpContext.Session.GetInt32("LoggedUserId") && rsvp.WeddingId == weddingid); if (existingRSVP == null) { UserWeddingRSVP newRSVP = new UserWeddingRSVP() { UserId = (int)HttpContext.Session.GetInt32("LoggedUserId"), WeddingId = weddingid }; db.UserWeddingRSVPs.Add(newRSVP); } else { db.UserWeddingRSVPs.Remove(existingRSVP); } db.SaveChanges(); return(RedirectToAction("Dashboard")); }