public ContinentStoryRecords GetContinentStories(int NumberPerContinent) { SqlConnection con = null; ContinentStoryRecords results = new ContinentStoryRecords(); try { con = new SqlConnection(System.Environment.GetEnvironmentVariable("NewsConnectionString", EnvironmentVariableTarget.Process)); con.Open(); using (var db = new Database(con)) { results.NorthAmerica = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerContinent}) * FROM Stories WHERE Providers.Continent = N'North America' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); results.SouthAmerica = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerContinent}) * FROM Stories WHERE Providers.Continent = N'South America' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); results.Europe = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerContinent}) * FROM Stories WHERE Providers.Continent = N'Europe' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); results.Asia = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerContinent}) * FROM Stories WHERE Providers.Continent = N'Asia' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); results.Africa = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerContinent}) * FROM Stories WHERE Providers.Continent = N'Africa' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); results.Australia = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerContinent}) * FROM Stories WHERE Providers.Continent = N'Australia' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); } } catch (Exception ex) { System.Diagnostics.Trace.TraceError("NosyRepo error in GetContinentStories. " + ex.ToString()); } finally { if (con != null) { con.Close(); } } return(results); }
public ActionResult <ContinentStoryRecords> Continents([FromQuery] int count = 10, [FromQuery] string displayLanguage = "en") { NosyBot.Services.Repositories.NosyRepository repo = new NosyBot.Services.Repositories.NosyRepository(); ContinentStoryRecords records = repo.GetContinentStories(count); TranslateCommand translate = new TranslateCommand() { DisplayLanguage = displayLanguage }; // Translate NA foreach (StoryRecord story in records.NorthAmerica) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate SA foreach (StoryRecord story in records.SouthAmerica) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate EU foreach (StoryRecord story in records.Europe) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate AS foreach (StoryRecord story in records.Asia) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate AF foreach (StoryRecord story in records.Africa) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate AU foreach (StoryRecord story in records.Australia) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } NosyBot.Services.Utilities.ServiceProxies.GetTranslations(translate); return(records); }