private CommentDto MapReceivedComment(Comment commentMapFrom) { var commentMapper = new CommentMapper(); var commentDTO = commentMapper.MapToCommentDto(commentMapFrom); if (commentMapFrom.CreatedBy != null) { var userMapper = new BlogUserMapper(); commentDTO.CreatedBy = userMapper.MapToBlogUserDto(commentMapFrom.CreatedBy); } if (commentMapFrom.RelatedTo != null) { var postMapper = new PostMapper(); commentDTO.RelatedTo = postMapper.MapToPostDto(commentMapFrom.RelatedTo); } return(commentDTO); }
private BlogDto MapReceivedBlog(Blog blogMapFrom) { var blogMapper = new BlogMapper(); var categoryMapper = new CategoryMapper(); BlogDto blogDTO = blogMapper.MapToBlogDto(blogMapFrom); if (blogMapFrom.BlogCategories != null) { blogDTO.BlogCategories = categoryMapper.MapToCategoryDtoList(blogMapFrom.BlogCategories); } if (blogMapFrom.BlogPosts != null) { var postMapper = new PostMapper(); var postDTOList = new List <PostDto>(); foreach (var post in blogMapFrom.BlogPosts) { var postDTOToAdd = postMapper.MapToPostDto(post); if (post.PostCategories != null) { postDTOToAdd.PostCategories = categoryMapper.MapToCategoryDtoList(post.PostCategories); } postDTOList.Add(postDTOToAdd); } blogDTO.BlogPosts = postDTOList; } if (blogMapFrom.CreatedBy != null) { var userMapper = new BlogUserMapper(); blogDTO.CreatedBy = userMapper.MapToBlogUserDto(blogMapFrom.CreatedBy); } return(blogDTO); }
private PostDto MapReceivedPost(Post postMapFrom) { var postMapper = new PostMapper(); PostDto postDTO = postMapper.MapToPostDto(postMapFrom); if (postMapFrom.RelatedTo != null) { var blogMapper = new BlogMapper(); postDTO.RelatedTo = blogMapper.MapToBlogDto(postMapFrom.RelatedTo); } if (postMapFrom.PostCategories != null) { var categoryMapper = new CategoryMapper(); postDTO.PostCategories = categoryMapper.MapToCategoryDtoList(postMapFrom.PostCategories); } if (postMapFrom.PostComments != null) { var commentMapper = new CommentMapper(); var userMapper = new BlogUserMapper(); var commentDTOList = new List <CommentDto>(); foreach (var comment in postMapFrom.PostComments) { var commentDTOToAdd = commentMapper.MapToCommentDto(comment); if (comment.CreatedBy != null) { commentDTOToAdd.CreatedBy = userMapper.MapToBlogUserDto(comment.CreatedBy); } commentDTOList.Add(commentDTOToAdd); } postDTO.PostComments = commentDTOList; } return(postDTO); }