Example #1
0
        public static ClientDataSet.EntityNodeDataTable GetEntityNodesTree(Guid organizationId, Guid?instanceId, Guid entityId, string entityName)
        {
            ClientDataSet.EntityNodeDataTable table = null;
            using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
            {
                table = adapter.GetEntityNodesByEntityId(entityId, organizationId, instanceId);
            }

            string customRootNodeText = EntityFieldProvider.Entities[entityId.ToString()].CustomRootNodeText;

            ClientDataSet.EntityNodeRow rootRow = table.NewEntityNodeRow();
            rootRow.EntityNodeId = Guid.Empty;
            if (!string.IsNullOrEmpty(customRootNodeText))
            {
                rootRow.Name = customRootNodeText.Replace("#organizationName#", UserContext.Current.Organization.Name);
            }
            else
            {
                rootRow.Name = entityName;
            }
            rootRow.EntityId       = entityId;
            rootRow.OrganizationId = organizationId;
            rootRow.SetParentEntityNodeIdNull();
            table.AddEntityNodeRow(rootRow);

            foreach (ClientDataSet.EntityNodeRow row in table)
            {
                if (row.EntityNodeId != Guid.Empty)
                {
                    if (row.IsParentEntityNodeIdNull())
                    {
                        row.ParentEntityNodeId = Guid.Empty;
                    }
                }
            }

            table.AcceptChanges();

            return(table);
        }
Example #2
0
        /// <summary>
        /// Changes the parent of the specified entity node.
        /// </summary>
        /// <param name="entityNodeId">The identifier of the entity node.</param>
        /// <param name="parentEntityNodeId">The identifier of new parent of the entity node.</param>
        public static void ChangeParentEntityNode(Guid entityNodeId, Guid?parentEntityNodeId)
        {
            Guid organizationId = UserContext.Current.OrganizationId;

            ClientDataSet.EntityNodeRow row = GetEntityNode(entityNodeId, organizationId);
            if (row != null)
            {
                if (parentEntityNodeId.HasValue && (parentEntityNodeId.Value != Guid.Empty))
                {
                    row.ParentEntityNodeId = parentEntityNodeId.Value;
                }
                else
                {
                    row.SetParentEntityNodeIdNull();
                }

                using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
                {
                    adapter.Update(row);
                }
            }
        }