public ResourceStructureModel()
 {
     Id                               = 0;
     Name                             = "";
     Description                      = "";
     AllResourceStructures            = new List <ResourceStructureModel>();
     ResourceStructureAttributeUsages = new List <ResourceStructureAttributeUsageModel>();
     SelectedItem                     = new ResourceStructureAttributeModel();
     FirstCreated                     = false;
     //Parent = new ResourceStructureModel();
 }
        public ResourceStructureModel(RSE.ResourceStructure resourceStructure)
        {
            Id                               = resourceStructure.Id;
            Name                             = resourceStructure.Name;
            Description                      = resourceStructure.Description;
            AllResourceStructures            = new List <ResourceStructureModel>();
            ResourceStructureAttributeUsages = new List <ResourceStructureAttributeUsageModel>();

            using (ResourceStructureManager rManager = new ResourceStructureManager())
                using (ResourceStructureAttributeManager rsaManager = new ResourceStructureAttributeManager())
                {
                    if (resourceStructure.Parent != null)
                    {
                        RSE.ResourceStructure parent = rManager.GetResourceStructureById(resourceStructure.Parent.Id);
                        Parent = Convert(parent);
                        //Get Parent attributes(usages) and add it to ResourceStructureAttributeUsages List
                        List <ResourceAttributeUsage> parentUsages = rsaManager.GetResourceStructureAttributeUsagesByRSId(Parent.Id);
                        if (parentUsages.Count > 0)
                        {
                            foreach (ResourceAttributeUsage usage in parentUsages)
                            {
                                ResourceStructureAttributeUsages.Add(new ResourceStructureAttributeUsageModel(usage.Id, usage.ResourceStructureAttribute.Id, Parent.Name));
                            }
                        }
                    }
                    else
                    {
                        Parent = null;
                    }


                    List <ResourceAttributeUsage> usages = rsaManager.GetResourceStructureAttributeUsagesByRSId(resourceStructure.Id);

                    if (usages.Count > 0)
                    {
                        foreach (ResourceAttributeUsage usage in usages)
                        {
                            ResourceStructureAttributeUsages.Add(new ResourceStructureAttributeUsageModel(usage.Id, usage.ResourceStructureAttribute.Id, null));
                        }
                    }

                    SelectedItem = new ResourceStructureAttributeModel();
                }
        }