From 3a403441ac862146cb7006edf81794707b9eb08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kan=20Edling?= Date: Fri, 26 Apr 2019 11:17:14 +0200 Subject: [PATCH] Fixed block group items for posts. Fixes #577 --- .../Repositories/PostRepository.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/data/Piranha.Data.EF/Repositories/PostRepository.cs b/data/Piranha.Data.EF/Repositories/PostRepository.cs index 4927439d2..949d00198 100644 --- a/data/Piranha.Data.EF/Repositories/PostRepository.cs +++ b/data/Piranha.Data.EF/Repositories/PostRepository.cs @@ -540,11 +540,19 @@ private void Process(Data.Post post, T model) where T : Models.PostBase { if (post.Blocks.Count > 0) { - var blocks = post.Blocks - .OrderBy(b => b.SortOrder) - .Select(b => b.Block) - .ToList(); - model.Blocks = _contentService.TransformBlocks(blocks); + foreach (var postBlock in post.Blocks.OrderBy(b => b.SortOrder)) + { + if (postBlock.ParentId.HasValue) + { + var parent = post.Blocks.FirstOrDefault(b => b.BlockId == postBlock.ParentId.Value); + if (parent != null) + { + postBlock.Block.ParentId = parent.Block.Id; + } + } + } + model.Blocks = _contentService.TransformBlocks(post.Blocks.OrderBy(b => b.SortOrder).Select(b => b.Block)); + } } }