Ejemplo n.º 1
0
 public IResponseMessage GetByPublishDate(string content)
 {
     var wxArticles = new List<ResponseMessageNews.Article>();
     using (var db = new WeChatDbContext())
     {
         var items = from item in db.Articles
                     where item.Published == content
                     orderby item.Published descending
                     select item;
         if (items.Count() == 0)
             return new ResponseMessageText("无此日期的文章,请尝试其他");
         foreach (var item in items)
         {
             var wxArticle = new ResponseMessageNews.Article
             {
                 Description = item.Description,
                 Title = item.Title,
                 PicUrl = new Uri(item.PicUrl),
                 Url = new Uri(item.Url)
             };
             wxArticles.Add(wxArticle);
         }
     }
     return new ResponseMessageNews(wxArticles.ToArray());
 }
Ejemplo n.º 2
0
        public IResponseMessage GetAllTags()
        {
            var tags = new HashSet<string>();
            using (var db = new WeChatDbContext())
            {
                var query = from item in db.Articles
                            select item.Tags;

                foreach (var item in query)
                {
                    var split = item.Split(' ');
                    foreach (var tag in split)
                    {
                        tags.Add(tag);
                    }
                }
            }
            return new ResponseMessageText(string.Join(" ", tags.ToArray()));
        }
Ejemplo n.º 3
0
 public IResponseMessage GetTop()
 {
     var wxArticles = new List<ResponseMessageNews.Article>();
     using (var db = new WeChatDbContext())
     {
         var items = from item in db.Articles
                     orderby item.Published descending
                     select item;
         foreach (var item in items.Take(5))
         {
             var wxArticle = new ResponseMessageNews.Article
             {
                 Description = item.Description,
                 Title = item.Title,
                 PicUrl = new Uri(item.PicUrl),
                 Url = new Uri(item.Url)
             };
             wxArticles.Add(wxArticle);
         }
     }
     return new ResponseMessageNews(wxArticles.ToArray());
 }
Ejemplo n.º 4
0
 public ArticleManager()
 {
     _db = new WeChatDbContext();
 }
Ejemplo n.º 5
0
 internal IResponseMessage GetByTag(string content)
 {
     var wxArticles = new List<ResponseMessageNews.Article>();
     using (var db = new WeChatDbContext())
     {
         var items = from item in db.Articles
                     where item.Tags.Contains(content)
                     orderby item.Published descending
                     select item;
         if (items.Count() == 0)
             return null;
         foreach (var item in items.Take(10))
         {
             var wxArticle = new ResponseMessageNews.Article
             {
                 Description = item.Description,
                 Title = item.Title,
                 PicUrl = new Uri(item.PicUrl),
                 Url = new Uri(item.Url)
             };
             wxArticles.Add(wxArticle);
         }
     }
     return new ResponseMessageNews(wxArticles.ToArray());
 }