public async Task <ActionResult> Index() { var sourceName = Request.QueryString["s"]; var url = CommonTools.Decrypt(Request.QueryString["u"]); TempData["SourceName"] = sourceName; try { return(View(await NewsPileUps.GetDetailBySourceName(url, sourceName))); } catch (Exception ex) { TempData["NotFound"] = "Sorry! News detail is not available anymore!"; return(View()); } }
public ActionResult GetLatestNewsPileUps(NewsPileUp.RssSource sourceName) { try { var cachesourceName = System.Runtime.Caching.MemoryCache.Default[sourceName.ToString()]; if (cachesourceName == null) { var htmlString = ""; var isLine = false; var latestNewsPileUps = Task.Run(() => NewsPileUps.GetLatestBySourceName(sourceName)).Result; if (!latestNewsPileUps.Any()) { return(Content(htmlString, "text/html")); } var path = Server.MapPath(ConfigurationManager.AppSettings["HtmlTemplatesPath"]); if (sourceName == NewsPileUp.RssSource.OilPrice) { htmlString = GenerationCardTemplate(path, sourceName, latestNewsPileUps); } else { foreach (var news in latestNewsPileUps) { if (string.IsNullOrEmpty(news.ImageUrl) && string.IsNullOrEmpty(news.Summary)) { isLine = true; htmlString += string.Format( System.IO.File.ReadAllText(path + "Line.html"), news.Title, CommonTools.Encrypt(news.Url), sourceName); } else if (string.IsNullOrEmpty(news.ImageUrl) && !string.IsNullOrEmpty(news.Summary)) { htmlString += string.Format( System.IO.File.ReadAllText(path + "WithSummary.html"), news.Title, news.Summary, CommonTools.Encrypt(news.Url), sourceName); } else { htmlString += string.Format( System.IO.File.ReadAllText(path + (sourceName == NewsPileUp.RssSource.EnergyVoice ? "SmallImageLine.html" : "ImageLine.html")), news.ImageUrl, news.Title, news.Summary, CommonTools.Encrypt(news.Url), sourceName); } } } htmlString = isLine ? $"<div class=\"well line-wrapper col-lg-12 col-md-12 col-sm-12 col-xs-12 text-left animated fadeIn x-slow-animated\">{htmlString}</div>" : htmlString; System.Runtime.Caching.MemoryCache.Default[sourceName.ToString()] = htmlString; return(Content(htmlString, "text/html")); } else { return(Content(cachesourceName.ToString(), "text/html")); } } catch (Exception ex) { var message = $"Message: {ex.Message} \t Date: {DateTime.Now}"; System.IO.File.WriteAllText(Server.MapPath(ConfigurationManager.AppSettings["LogPath"] + "log.txt"), message, Encoding.UTF8); return(Content("", "text/html")); } }