private async Task <List <Application> > GetGooglePlayApplicationsAsync(string keyword) { using (var db = new GooglePlayAppsRepository()) { var apps = db.SearchRequests .Include(s => s.Applications) .ThenInclude(a => a.Screenshots) .FirstOrDefault(s => s.Keyword == keyword)?.Applications.ToList(); if (apps == null) { await Console.Out.WriteLineAsync("Get data from web resourse"); List <string> top3GooglePlayAppsNames = await _googlePlayClient.GetTop3SearchSuggestAsync(keyword); var getGooglePlayAppsInfoTask = top3GooglePlayAppsNames.Select(async n => { return(await _googlePlayClient.GetApplicationInfo(n)); }); var applications = await Task.WhenAll(getGooglePlayAppsInfoTask); db.SearchRequests.Add(new SearchRequest { Keyword = keyword, Applications = applications }); db.SaveChanges(); return(applications.ToList()); } await Console.Out.WriteLineAsync("Get data from database"); return(apps); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } using (var appStoreContext = new AppStoreAppsRepository()) { appStoreContext.Database.Migrate(); } using (var googlePlayContext = new GooglePlayAppsRepository()) { googlePlayContext.Database.Migrate(); } app.UseMvc(); }