Blog.Logic.Core.PostsLogic.GetRelatedPosts C# (CSharp) Method

GetRelatedPosts() public method

public GetRelatedPosts ( int postId ) : RelatedPosts
postId int
return Blog.Common.Contracts.ViewModels.RelatedPosts
        public RelatedPosts GetRelatedPosts(int postId)
        {
            try
            {
                var relatedPosts = new RelatedPosts();
                var post = GetPost(postId);

                var postByTags = new List<Post>();
                if (post.Tags == null || post.Tags.Count == 0)
                {
                    relatedPosts.PostsByTags = new List<Post>();
                }
                else
                {
                    post.Tags.ForEach(a =>
                    {
                        var tPosts = GetPostsByTag(a.TagName);
                        tPosts.ForEach(b =>
                        {
                            var canAdd = postByTags.All(p => p.Id != b.Id);
                            if (canAdd) postByTags.Add(b);
                        });
                    });
                    relatedPosts.PostsByTags = postByTags.Where(p => p.Id != postId).ToList();
                }

                var postsByUser = GetPostsByUser(post.User.Id).Where(p => p.Id != postId).ToList();
                relatedPosts.PostsByUser = postsByUser;

                return relatedPosts;
            }
            catch (Exception ex)
            {
                throw new BlogException(ex.Message, ex.InnerException);
            }
        }