private IEnumerable <User> sort(IEnumerable <User> users) { int uId = Int32.Parse(Session["UserId"].ToString()); User currentUser = db.Users.Find(uId); List <Int32> scores = new List <Int32>(); int score; foreach (User user in users) { score = 0; if (currentUser.Gender != null) { if (user.Gender == null) { score += 20; } else if ((currentUser.Gender != "Other" && user.Gender != currentUser.Gender) || (currentUser.Gender == "Other" && user.Gender == "Other")) { score += 50; } } if (currentUser.Occupation != null && user.Occupation != null && JaroWinklerDistance.proximity(currentUser.Occupation, user.Occupation) >= 0.8) { score += 10; } if (currentUser.City != null && user.City != null && JaroWinklerDistance.proximity(currentUser.City, user.City) >= 0.8) { score += 10; } if (currentUser.Likes != null && user.Likes != null) { score += matchWordsScore(currentUser.Likes, user.Likes); } if (currentUser.Dislikes != null && user.Dislikes != null) { score += matchWordsScore(currentUser.Dislikes, user.Dislikes); } if (currentUser.Hobbies != null && user.Hobbies != null) { score += matchWordsScore(currentUser.Hobbies, user.Hobbies); } if (currentUser.Bio != null && user.Bio != null) { score += matchWordsScore(currentUser.Bio, user.Bio); } scores.Add(score); } var orderedZip = scores.Zip(users, (x, y) => new { x, y }) .OrderByDescending(pair => pair.x) .ToList(); users = orderedZip.Select(pair => pair.y).ToList(); return(users); }