private string FindPossibleSolution() { string possibleSolution = ""; if (IncidentTicket.Solution != null || IncidentTicket.Solution == "") { return(possibleSolution); } int mostSameWords = 0; IncidentTicket bestSolution = new IncidentTicket(); bool bestSolutionChanged = false; foreach (IncidentTicket incidentTicket in incidentTickets) { if (incidentTicket.Solution == null || incidentTicket.Solution == "" || IncidentTicket.Equals(incidentTicket)) { continue; } if (IncidentTicket.Type == incidentTicket.Type) { if (IncidentTicket.Subject.ToUpper() == incidentTicket.Subject.ToUpper() || IncidentTicket.Subject.ToUpper().Contains(incidentTicket.Subject.ToUpper()) || incidentTicket.Subject.ToUpper().Contains(IncidentTicket.Subject.ToUpper())) { int sameWords = 0; if (IncidentTicket.Description != null && IncidentTicket.Description != "" && incidentTicket.Description != null && incidentTicket.Description != "") { string[] descriptionWords = incidentTicket.Description.Split(' '); foreach (string word in descriptionWords) { if (IncidentTicket.Description.ToUpper().Contains(word.ToUpper())) { sameWords++; } } } if (!bestSolutionChanged && mostSameWords == sameWords) { bestSolution = incidentTicket; bestSolutionChanged = true; } else if (mostSameWords < sameWords) { bestSolution = incidentTicket; bestSolutionChanged = true; } } } } if (bestSolutionChanged) { return(bestSolution.Solution); } else { return(possibleSolution); } }