public IActionResult deleteactivity(int id) { int?active = HttpContext.Session.GetInt32("ActiveUser"); if (active == null) { return(Redirect("/")); } else { List <Activity> toremove = _context.Activities.Where(i => i.ActivityId == id).Include(u => u.user).Include(r => r.Joined).ToList(); if (toremove.Count < 1) { return(Redirect("/home")); } Activity remove = toremove[0]; if (remove.user.UserId != active) { return(Redirect("/home")); } else { _context.RemoveRange(_context.Joined.Where(w => w.ActivitiesId == remove.ActivityId)); _context.Activities.Remove(remove); _context.SaveChanges(); return(Redirect("/home")); } } }