public ActionResult Leave(LeaveEventModel viewModel) { //Get all the event data and make sure the user is in the event MeetupModel model = new MeetupModel(); int? infoId = this.UserId(); if (infoId is null) { return(RedirectToAction("Index", "Home")); } viewModel.EventInformation = model.Events.SingleOrDefault(e => e.Id == viewModel.EventId && e.Invites.Any(u => u.UserId == infoId)); if (viewModel.EventInformation is null) { return(RedirectToAction("Index", "Home")); } //Remove invite model.Invites.Remove(viewModel.EventInformation.Invites.SingleOrDefault(u => u.UserId == infoId)); model.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// An action returning a page where the user confirms they want to leave /// </summary> /// <param name="id">The event the user wants to leave</param> /// <returns>if the user is in the event: Returns a page where the user can leave the event</returns> public ActionResult Leave(int id) { //Get event and make sure the user is in it MeetupModel model = new MeetupModel(); int? infoId = this.UserId(); if (infoId is null) { return(RedirectToAction("Index", "Home")); } LeaveEventModel viewModel = new LeaveEventModel(); viewModel.EventInformation = model.Events.SingleOrDefault(e => e.Id == id && e.Invites.Any(u => u.UserId == infoId)); if (viewModel.EventInformation is null) { return(RedirectToAction("Index", "Home")); } viewModel.EventId = viewModel.EventInformation.Id; return(View(viewModel)); }