Exemple #1
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();
        }
Exemple #2
0
 public MyBlogRepository()
 {
     db = new UsersContext();
     publications = new PublicationContext();
 }
Exemple #3
0
 public MyBlogRepository()
 {
     db = new MyBlogEntities();
     publications = new PublicationContext();
 }