public void BanUser(Tweet tweet, string streamName) { TwitterStream ts = streamManager.GetStream(streamName); if (ts != null) { Tweet serverTweet = ts._tweetRepo.Find(t => t.Id == tweet.Id && t.Event.Name == streamName).SingleOrDefault(); User alreadyBanned = ts._userRepo.Find(user => user.UserId == serverTweet.UserId && user.Event.Name == streamName).SingleOrDefault(); if (alreadyBanned == null && serverTweet != null) { User newUser = new User(serverTweet.UserId, serverTweet.Handle); newUser.Type = Common.BanType; newUser.Event = ts.GetStreamEvent(); ts._userRepo.Add(newUser); List <Tweet> tweetsToDelete = ts._tweetRepo.Find(t => (t.UserId == serverTweet.UserId) && (t.Event.Name == streamName)).ToList(); foreach (Tweet aTweet in tweetsToDelete) { RemoveTweet(aTweet.Id, streamName); } Clients.Group(streamName).userBanned(ts.GetBannedUsers()); ts.RemoveTweetsByHandle(newUser.Handle); } } }