public void SaveArticle(Article article, List<ContentImage> updatedImages)
        {
            var dbEntry = context.Articles.Find(article.ArticleId);
            if (dbEntry != null)
            {
                dbEntry.Name = article.Name;
                dbEntry.Description = article.Description;
                dbEntry.Content = article.Content;

                dbEntry.Tags.ToList().ForEach(t => dbEntry.Tags.Remove(t));

                dbEntry.Tags = article.Tags;
            }
            else
            {
                context.Articles.Add(article);
            }

            context.Images.AddRange(updatedImages);
            context.SaveChanges();
        }
Пример #2
0
        public void TestArticleRepository()
        {
            var articleRepository = new EfArticleRepository();

            var article = new Article("4525D21E-460C-44C9-AA6D-E791261EC843");
            article.Name = "Какое-то имя";
            article.Content = "Какое-то содержимое";
            article.Description = "Какое-то описание";
            article.Tags = new List<Tag>(3)
            {
                new Tag{Name = "Тэг1"},
                new Tag{Name = "Тэг2"},
                new Tag{Name = "Тэг3"},
            };

            articleRepository.SaveArticle(article, null);
        }