private string[] GetRecommendations(List <int> topVisitorProducts, int numberOfRecommendations, string database) { Dictionary <int, double> recommendations = new Dictionary <int, double>(); foreach (int product in topVisitorProducts) { Dictionary <int, double> topProductRecommendation = _db.GetTopProductRecommendation(product, database).Result; foreach (int recommendation in topProductRecommendation.Keys) { if (recommendations.Keys.Contains(recommendation)) { recommendations[recommendation] += topProductRecommendation[recommendation]; } else { recommendations.Add(recommendation, topProductRecommendation[recommendation]); } } } Dictionary <int, double> finalRecommendation = SortRecommendation(recommendations); if (finalRecommendation.Count < numberOfRecommendations) { finalRecommendation = FillFromDefault(finalRecommendation, database, numberOfRecommendations); if (finalRecommendation.Count < numberOfRecommendations) { numberOfRecommendations = finalRecommendation.Count; } } string[] finalResult = new string[numberOfRecommendations]; for (int i = 0; i < numberOfRecommendations; i++) { finalResult[i] = finalRecommendation.Keys.ElementAt(i).ToString(); } return(finalResult); }