public static Post ToDto(Db.Post post)
{
if (post == null) return null;
var postLikes = post.PostLikes != null
? post.PostLikes.Select(PostLikeMapper.ToDto).ToList()
: null;
var contents = post.PostContents != null
? post.PostContents.Select(PostContentMapper.ToDto).ToList()
: null;
var comments = post.Comments != null
? post.Comments.Select(CommentMapper.ToDto).ToList()
: null;
var tags = post.Tags != null
? post.Tags.Select(TagMapper.ToDto).ToList()
: null;
var viewCounts = post.ViewCounts != null
? post.ViewCounts.Select(ViewCountMapper.ToDto).ToList()
: null;
var communities = post.Communities != null
? post.Communities.Select(CommunityMapper.ToDto).ToList()
: null;
return new Post
{
Id = post.PostId,
PostTitle = post.PostTitle,
PostMessage = post.PostMessage,
PostLikes = postLikes,
PostContents = contents,
Comments = comments,
ViewCounts = viewCounts,
Communities = communities,
User = post.User != null ? UserMapper.ToDto(post.User) : null,
Tags = tags,
CreatedBy = post.CreatedBy,
CreatedDate = post.CreatedDate,
ModifiedBy = post.ModifiedBy,
ModifiedDate = post.ModifiedDate
};
}