/// <summary> /// Creates a list of incidents types to be displayed to the user. /// </summary> /// <param name="searchText"> /// An optional search parameter. /// If left blank, all incident types are returned. /// If specified, both the incident type name and any associtated keywords are matched.</param> /// <returns>A list of incident types.</returns> internal void BuildIncidentTypesList(string searchText = "") { //first search through the filtered list and remove any incident types that don't have a matching name or keyword List <IncidentType> toDelete = new List <IncidentType>(); foreach (IncidentType type in IncidentTypes) { bool matching = false; if (type.Name.ToUpper().Contains(searchText.ToUpper())) { matching = true; } foreach (string keyword in type.Keywords) { if (keyword.ToUpper().Contains(searchText.ToUpper())) { matching = true; } } if (!matching) { toDelete.Add(type); } } foreach (IncidentType type in toDelete) { filteredIncidentTypes.Remove(type); } //then search through the full list and add any incident types that DO have a matching name or keyword List <IncidentType> toAdd = new List <IncidentType>(); foreach (IncidentType type in fullList) { bool matching = false; if (type.Name.ToUpper().Contains(searchText.ToUpper())) { matching = true; } foreach (string keyword in type.Keywords) { if (keyword.ToUpper().Contains(searchText.ToUpper())) { matching = true; } } if (matching) { toAdd.Add(type); } } foreach (IncidentType type in toAdd) { if (!filteredIncidentTypes.Contains(type)) { filteredIncidentTypes.Add(type); } } }