public List <TrendsVM> GetTrends() { List <TrendsVM> myList = new List <TrendsVM>(); DateTime now = DateTime.Now; List <Tweets> listTweets = db.Tweets.ToList(); foreach (var item in listTweets) { if (item.TweetDate > now.AddHours(-72) && item.TweetDate <= now) { string[] wordList = item.Content.Split(' '); foreach (var item2 in wordList) { if (item2.Length < 4) { continue; } TrendsVM temp = db.tsp_WordCount(item2).Select(x => new TrendsVM { word = x.word, count = (int)x.count }).FirstOrDefault(); bool exists = false; foreach (var myItem in myList) { if (item2.Equals(myItem.word)) { exists = true; } } if (!exists && temp.count != 0) { myList.Add(temp); } } } } return(myList.OrderByDescending(x => x.count).Take(10).ToList()); }