public async Task <ActionResult> Index(ItunesSearchModel itunesSearch) { var searchString = RemoveWhitespace(itunesSearch.searchString); var searchType = itunesSearch.searchType; string baseUri = "https://itunes.apple.com/search?"; string searchParameters = $"term={searchString}&entity={searchType}"; string apiUrl = baseUri + searchParameters; var lastreleaseDate = DateTime.Now.AddYears(-8); var model = new ItunesSearchModel(); model.showResultsSection = true; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(apiUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(apiUrl); if (response.IsSuccessStatusCode) { var searchContent = await response.Content.ReadAsStringAsync(); var acutalData = Newtonsoft.Json.JsonConvert.DeserializeObject <ItunesSearchModel>(searchContent); model.results = acutalData.results.Where(l => l.releaseDate >= lastreleaseDate).ToList(); } } return(View("Index", model)); }
public ActionResult Index() { var model = new ItunesSearchModel(); return(View("Index", model)); }