public WorldStoryRecords GetRegionStories(int NumberPerRegion) { SqlConnection con = null; WorldStoryRecords results = new WorldStoryRecords(); try { con = new SqlConnection(System.Environment.GetEnvironmentVariable("NewsConnectionString", EnvironmentVariableTarget.Process)); con.Open(); using (var db = new Database(con)) { results.Americas = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerRegion}) * FROM Stories WHERE Providers.Region = N'americas' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); results.EMEA = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerRegion}) * FROM Stories WHERE Providers.Region = N'emea' AND Stories.ProviderId = Providers.Id ORDER BY Stories.PublishDate DESC) AS st ORDER BY st.PublishDate DESC"); results.APAC = db.Fetch <StoryRecord>($"SELECT * FROM Providers CROSS APPLY (SELECT TOP ({NumberPerRegion}) * FROM Stories WHERE Providers.Region = N'apac' 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 GetLatestStories. " + ex.ToString()); } finally { if (con != null) { con.Close(); } } return(results); }
public ActionResult <WorldStoryRecords> Get([FromQuery] int count = 10, [FromQuery] string displayLanguage = "en") { NosyBot.Services.Repositories.NosyRepository repo = new NosyBot.Services.Repositories.NosyRepository(); WorldStoryRecords records = repo.GetRegionStories(count); TranslateCommand translate = new TranslateCommand() { DisplayLanguage = displayLanguage }; // Now translate AMERICAS if necessary foreach (StoryRecord story in records.Americas) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } //story.TranslatedTitle = NosyBot.Services.Utilities.ServiceProxies.GetTranslation(story.Title, story.Language, displayLanguage).Result; } // EMEA foreach (StoryRecord story in records.EMEA) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } //story.TranslatedTitle = NosyBot.Services.Utilities.ServiceProxies.GetTranslation(story.Title, story.Language, displayLanguage).Result; } // APAC foreach (StoryRecord story in records.APAC) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } //story.TranslatedTitle = NosyBot.Services.Utilities.ServiceProxies.GetTranslation(story.Title, story.Language, displayLanguage).Result; } NosyBot.Services.Utilities.ServiceProxies.GetTranslations(translate); return(records); }