public async Task <IActionResult> Autocomplete_Get(string id, string feedUrl) { try { feedUrl = !string.IsNullOrEmpty(feedUrl) ? feedUrl : NuGetV3SearchService.DefaultServiceIndexUrl; var searchService = new NuGetV3SearchService(feedUrl); var result = await searchService.AutocompleteAsync( query : id, take : 20, prerelease : true); return(Json(result.Data)); } catch (InvalidOperationException) { // intentional return(Json(new string[] { })); } catch (HttpRequestException) { // intentional return(Json(new string[] { })); } }
public async Task <IActionResult> Index_Get(HomeViewModel model) { // Ensure we have a model model.FeedUrl = !string.IsNullOrEmpty(model.FeedUrl) ? model.FeedUrl : NuGetV3SearchService.DefaultServiceIndexUrl; //model.PackageId = !string.IsNullOrEmpty(model.PackageId) // ? model.PackageId // : "EntityFramework"; //model.VersionRange = !string.IsNullOrEmpty(model.VersionRange) // ? model.VersionRange // : "6.0.*"; if (!string.IsNullOrEmpty(model.PackageId)) { // Perform search and fetch all versions VersionRange versionRange; if (VersionRange.TryParse(model.VersionRange, out versionRange)) { model.NuGetVersionRange = versionRange; } try { var searchService = new NuGetV3SearchService(model.FeedUrl); var versions = await searchService.AutocompleteAsync( id : model.PackageId.ToLowerInvariant(), prerelease : true); foreach (var version in versions.Data) { model.Versions.Add(NuGetVersion.Parse(version)); } } catch (InvalidOperationException) { // intentional } catch (HttpRequestException) { // intentional } } return(View(model)); }