namespace InnovEnergy.API.DataModel; public static class DataExtensions { public static Folder GetOrCreateFolder(this Data data, IEnumerable path) { var parent = data.Root; var stack = new Stack(path.Reverse()); while (stack.Count > 0) { var childFolderName = stack.Pop(); var childFolder = parent.Folders.FirstOrDefault(f => f.Name == childFolderName); if (childFolder is null) { childFolder = new Folder { Name = childFolderName }; parent.Add(childFolder); } parent = childFolder; } return parent; } }