public static Tuple <bool, IEnumerable <SoftwareSearch> > GetFilteredSoftwareSearch(string filter) { bool valid = true; int majorVersion = 0; int minorVersion = 0; int patch = 0; string[] filterElements = filter.Split(UtilityManager.GetVersionDelimiter()); IEnumerable <SoftwareSearch> filteredSoftwareSearchList = new List <SoftwareSearch>(); if (filter.Trim().Length > 0) { if (filterElements.Length > 0) { if (!Int32.TryParse(filterElements[0], out majorVersion)) { // Error Handling, check with business owner how they want handled valid = false; } } if (filterElements.Length > 1) { if (!Int32.TryParse(filterElements[1], out minorVersion)) { // Error Handling valid = false; } } if (filterElements.Length > 2) { if (!Int32.TryParse(filterElements[2], out patch)) { // Error Handling valid = false; } } } if (valid) { IEnumerable <SoftwareSearch> softwareSearchList = GetAllSoftwareSearch(); filteredSoftwareSearchList = softwareSearchList.Where(item => item.MajorVersion > majorVersion) .Union(softwareSearchList.Where(item => item.MajorVersion == majorVersion && item.MinorVersion > minorVersion)) .Union(softwareSearchList.Where(item => item.MajorVersion == majorVersion && item.MinorVersion == minorVersion && item.Patch > patch)) .OrderBy(item => item.MajorVersion).ThenBy(item => item.MinorVersion).ThenBy(item => item.Patch).ThenBy(item => item.Name); } return(new Tuple <bool, IEnumerable <SoftwareSearch> >(valid, filteredSoftwareSearchList)); }
public SoftwareSearch(Software software) { Name = software.Name; Version = software.Version; int number; string[] searchTermElements = Version.Split(UtilityManager.GetVersionDelimiter()); if (searchTermElements.Length > 0) { if (Int32.TryParse(searchTermElements[0], out number)) { MajorVersion = number; } else { // Error Handling, check with business owner how they want handled } } if (searchTermElements.Length > 1) { if (Int32.TryParse(searchTermElements[1], out number)) { MinorVersion = number; } else { // Error Handling } } if (searchTermElements.Length > 2) { if (Int32.TryParse(searchTermElements[2], out number)) { Patch = number; } else { // Error Handling } } }