using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; namespace PRSDesktop { public class DocumentSetNode : INotifyPropertyChanged { private DocumentSetNodes _owner = null; public ObservableCollection Children => _owner.GetChilden(_id); private Guid _id; public Guid ID { get { return _id; } set { _id = value; RaisedOnPropertyChanged("ID"); } } private Guid _parent; public Guid Parent { get { return _parent; } set { _parent = value; RaisedOnPropertyChanged("Parent"); } } private string _description; public string Description { get { return _description; } set { _description = value; RaisedOnPropertyChanged("Description"); } } private string _details; public string Details { get { return _details; } set { _details = value; RaisedOnPropertyChanged("Details"); } } public Dictionary Blocks { get; private set; } public event PropertyChangedEventHandler PropertyChanged; public void RaisedOnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public DocumentSetNode(DocumentSetNodes owner) { _owner = owner; Blocks = new Dictionary(); foreach (var column in owner.Columns) Blocks[column] = ""; } public DocumentSetNode(DocumentSetNodes owner, Guid id, Guid parent) : this(owner) { _id = id; _parent = parent; } } public class DocumentSetNodes { private List _nodes = null; public ObservableCollection Nodes => new ObservableCollection(_nodes.Where(x=>x.Parent == Guid.Empty)); public IEnumerable Columns { get; private set; } public DocumentSetNodes(IEnumerable columns) { _nodes = new List(); Columns = columns; } public DocumentSetNode Add(Guid id, Guid parent) { var node = new DocumentSetNode(this, id, parent); _nodes.Add(node); return node; } public ObservableCollection GetChilden(Guid id) { return new ObservableCollection(_nodes.Where(x => x.Parent.Equals(id) && (x.ID != id))); } public DocumentSetNode? GetNode(Guid id) { return _nodes.FirstOrDefault(x => x.ID == id); } } }