コード例 #1
0
        public void CreateFullArticleEntity(FullArticleEntity fullArticle)
        {
            if (fullArticle == null)
            {
                return;
            }
            var article = new ArticleEntity()
            {
                Id           = fullArticle.Id,
                Title        = fullArticle.Title,
                CreationTime = fullArticle.CreationTime,
                Text         = fullArticle.Text,
                TitleImage   = fullArticle.TitleImage,
                UserId       = fullArticle.User.Id,
                BlogId       = fullArticle.Blog.Id
            };

            uow.ArticleRepository.Create(article.ToDalArticle());

            var articleTag =
                fullArticle.Tags.Select(x => new ArticleTagEntity()
            {
                ArticleId = fullArticle.Id, TagId = x.Id
            }.ToDalArticleTag());

            foreach (var item in articleTag)
            {
                uow.ArticleTagRepository.Create(item);
            }
            uow.Commit();
        }
コード例 #2
0
 //delete article with all comments
 public void DeleteArticle(FullArticleEntity fullArticle)
 {
     uow.ArticleRepository.Delete(fullArticle.ToDalArticle());
     uow.ArticleTagRepository.DeleteAllByArticle(fullArticle.Id);
     uow.CommentRepository.DeleteAllByArticle(fullArticle.Id);
     uow.Commit();
 }
コード例 #3
0
 //delete article with all comments
 public void DeleteArticle(FullArticleEntity fullArticle)
 {
     uow.ArticleRepository.Delete(fullArticle.ToDalArticle());
     uow.ArticleTagRepository.DeleteAllByArticle(fullArticle.Id);
     uow.CommentRepository.DeleteAllByArticle(fullArticle.Id);
     uow.Commit();
 }
コード例 #4
0
        public void CreateFullArticleEntity(FullArticleEntity fullArticle)
        {
            if (fullArticle == null)
                return;
            var article = new ArticleEntity()
            {
                Id = fullArticle.Id,
                Title = fullArticle.Title,
                CreationTime = fullArticle.CreationTime,
                Text = fullArticle.Text,
                TitleImage = fullArticle.TitleImage,
                UserId = fullArticle.User.Id,
                BlogId = fullArticle.Blog.Id
            };
            uow.ArticleRepository.Create(article.ToDalArticle());

            var articleTag =
                fullArticle.Tags.Select(x => new ArticleTagEntity() { ArticleId = fullArticle.Id, TagId = x.Id }.ToDalArticleTag());

            foreach (var item in articleTag)
            {
                uow.ArticleTagRepository.Create(item);
            }
            uow.Commit();
        }
コード例 #5
0
 public static DalArticle ToDalArticle(this FullArticleEntity article)
 {
     return(new DalArticle()
     {
         Id = article.Id,
         Title = article.Title,
         CreationTime = article.CreationTime,
         Text = article.Text,
         TitleImage = article.TitleImage,
         UserId = article.User.Id,
         BlogId = article.Blog.Id
     });
 }
コード例 #6
0
 public static FullArticleViewModel ToMvcFullArticle(this FullArticleEntity article)
 {
     return new FullArticleViewModel()
     {
         Id = article.Id,
         Title = article.Title,
         CreationTime = article.CreationTime,
         Text = article.Text,
         User = article.User.ToMvcUser(),
         TitleImage = article.TitleImage,
         Blog = article.Blog?.ToMvcSimpleBlog(),
         Tags = article.Tags.Select( x => x.ToMvcSimpleTag()),
         Comments = article.Comments.Select(x => x.ToMvcFullComment())
     };
 }
コード例 #7
0
        public FullArticleEntity GetFullArticleEntity(ArticleEntity e)
        {
            if (e == null)
            {
                return(null);
            }
            var result = new FullArticleEntity()
            {
                Id           = e.Id,
                Title        = e.Title,
                CreationTime = e.CreationTime,
                Text         = e.Text,
                User         = uow.UserRepository.GetById(e.UserId)?.ToBllUser(),
                TitleImage   = e.TitleImage,
                Blog         = uow.BlogRepository.GetById(e.BlogId)?.ToBllBlog(),
                Tags         = uow.ArticleTagRepository.GetAll().Where(tag => tag.ArticleId == e.Id).Select(x => uow.TagRepository.GetById(x.TagId)?.ToBllTag()),
                Comments     = uow.CommentRepository.GetAll().Where(comment => comment.ArticleId == e.Id).Select(x => x.ToFullCommentEntity())
            };

            return(result);
        }
コード例 #8
0
 public FullArticleEntity GetFullArticleEntity(ArticleEntity e)
 {
     if (e == null)
         return null;
     var result = new FullArticleEntity()
     {
         Id = e.Id,
         Title = e.Title,
         CreationTime = e.CreationTime,
         Text = e.Text,
         User = uow.UserRepository.GetById(e.UserId)?.ToBllUser(),
         TitleImage = e.TitleImage,
         Blog = uow.BlogRepository.GetById(e.BlogId)?.ToBllBlog(),
         Tags = uow.ArticleTagRepository.GetAll().Where(tag => tag.ArticleId == e.Id).Select(x => uow.TagRepository.GetById(x.TagId)?.ToBllTag()),
         Comments = uow.CommentRepository.GetAll().Where(comment => comment.ArticleId == e.Id).Select(x => x.ToFullCommentEntity())
     };
     return result;
 }