public string GetPreview(Article article)
        {
            //delte html tags
            string cleanArticle = Regex.Replace(article.ArticleText, @"<[\/]*[p|span|strong|em|strike|ul|ol|li|blockquote|a href=].*?>", string.Empty);
            string preview = "";

            for (int i = 0; i < cleanArticle.Length; i++)
            {
                // get first n symbols
                if (i < previewSymbolsCount)
                {
                    preview += cleanArticle[i];
                }
                else
                {
                    break;
                }
            }
            return preview;
        }
Пример #2
0
 private void AddArticle(Article article)
 {
     publications.Articles.Add(article);
     publications.SaveChanges();
 }
Пример #3
0
 public void DropPublication(int id)
 {
     Article delArticle = new Article();
     delArticle = publications.Articles.Find(id);
     publications.Articles.Remove(delArticle);
     publications.SaveChanges();
 }
Пример #4
0
 public void DeleteRestorePublication(int id)
 {
     Article delArticle = new Article();
     delArticle = publications.Articles.Find(id);
     delArticle.Deleted = !delArticle.Deleted;
     publications.Entry(delArticle).State = EntityState.Modified;
     publications.SaveChanges();
 }
Пример #5
0
        public void AddPublication(NewPublicationViewModel newPublication)
        {
            int articleId = newPublication.Id;
            Article newArticle = new Article {ArticleTitle = newPublication.Title, ArticleText = newPublication.ArticleText };
            if (articleId == 0)
            {
                AddArticle(newArticle);
                articleId = publications.Articles.OrderByDescending(x => x.Id).First<Article>().Id;
            }
            else
            {
                newArticle.Id = articleId;
                publications = new PublicationContext();
                publications.Entry(newArticle).State = EntityState.Modified;
                List<TagToArticle> curConnections = publications.TagToArticles.Where(x => x.ArticleId == articleId).Select(x => x).ToList();
                foreach (TagToArticle curEntity in curConnections)
                {
                    publications.TagToArticles.Remove(curEntity);
                }
            }
            List<string> allTags = new List<string>();
            if (newPublication.NewTags != null)
            {
                allTags = newPublication.NewTags.Split(splitSymbol).ToList<string>();
            }
            if (newPublication.SelectedTags != null)
            {
                foreach (int tagId in newPublication.SelectedTags)
                {
                    allTags.Add(Tags.Where(x => x.Id == tagId).Select(x => x.TagName).FirstOrDefault());
                }
            }
            foreach (string curTagName in allTags)
            {
                int tagId = GetTagId(curTagName);
                publications.TagToArticles.Add(new TagToArticle { ArticleId = articleId, TagId = tagId });
            }

            publications.SaveChanges();
        }