protected void Page_Load(object sender, EventArgs e)
        {
            List <Article> articleList = aArticleManager.GetArticleList();

            List <Article> customArticlList = new List <Article>();

            foreach (Article article in articleList)
            {
                Article customArticle = new Article();
                customArticle.Id = article.Id;

                string source = article.Description;
                var    reg    = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
                var    match  = reg.Match(source);
                if (match.Success)
                {
                    string encod = match.Groups["imgSrc"].Value;
                    customArticle.Image = encod;
                }

                string strippedDescription = Regex.Replace(article.Description, "<.*?>", string.Empty);
                int    length = strippedDescription.Length;
                if (length > 500)
                {
                    length = 500;
                }

                string customDescription = strippedDescription.Substring(0, length);
                customArticle.Description = customDescription;
                customArticle.Title       = article.Title;
                customArticlList.Add(customArticle);
            }

            AllPost.DataSource = customArticlList;
            AllPost.DataBind();
        }
Esempio n. 2
0
 public Task <List <Post> > GetPostsByUserId(int userId)
 {
     return(AllPost.Where(p => p.Id == userId).ToListAsync());
 }
Esempio n. 3
0
 public Task <Post> GetPostById(int id)
 {
     return(AllPost.Where(p => p.Id == id).FirstOrDefaultAsync());
 }
Esempio n. 4
0
 public Task <List <Post> > GetAllPost()
 {
     return(AllPost.ToListAsync());
 }