private TreeNode CreateNewTreeNode(string folder, int? parentId, int libraryId, BXCModelEntities context) { var nodeRepo = new TreeNodeRepository(context); var libraryRepo = new LibraryRepository(context); var newNode = new TreeNode { Name = folder, TreeNode1 = parentId == null ? null : nodeRepo.GetByID(parentId.Value), Library = libraryRepo.GetByID(libraryId) }; nodeRepo.AddTreeNode(newNode); return newNode; }