Exemple #1
0
        public void GetParent()
        {
            Organization org1 = Organization.Create();

            org1.Code     = StringFactory.NewGuid();
            org1.Name     = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();
            Assert.IsNotNull(org1);

            Organization org2 = Organization.Create();

            org2.Code     = StringFactory.NewGuid();
            org2.Name     = "org-test-name";
            org2.FullName = "org-test-fullname";
            org2.Save();

            org1.AddChild(org2);

            Organization org3 = org1.AddChild(org2);

            Assert.IsNotNull(org3);
            Assert.IsNotNull(org3.GetParent());

            org1.Delete();
            org1.RemoveChild(org2);
            org2.Delete();
            org3.Delete();
        }
Exemple #2
0
        void accessing_siblings()
        {
            Organization parent   = new Organization("parent", Guid.NewGuid());
            Organization childOne = new Organization("first child", Guid.NewGuid());
            Organization childTwo = new Organization("second child", Guid.NewGuid());

            context["when a parent node has multiple children"] = () =>
            {
                context["sibling nodes can navigate to one another"] = () =>
                {
                    parent.AddChild(childOne);
                    parent.AddChild(childTwo);

                    it["child one should see a child two node"] = () =>
                    {
                        var siblings = childOne.Siblings();
                        Assert.That(siblings, Is.Not.Null);
                        siblings.should_not_be_empty();
                        siblings.should_contain(childTwo);
                    };

                    it["child two node should see child one node"] = () =>
                    {
                        childTwo.Siblings().should_contain(childOne);
                    };
                };
            };
        }
        void accessing_siblings()
        {
            Organization parent = new Organization("parent", Guid.NewGuid());
            Organization childOne  = new Organization("first child", Guid.NewGuid());
            Organization childTwo  = new Organization("second child", Guid.NewGuid());

            context["when a parent node has multiple children"] = () =>
            {
                context["sibling nodes can navigate to one another"] = () =>
                {
                    parent.AddChild(childOne);
                    parent.AddChild(childTwo);

                    it["child one should see a child two node"] = () =>
                    {
                        var siblings = childOne.Siblings();
                        Assert.That(siblings, Is.Not.Null);
                        siblings.should_not_be_empty();
                        siblings.should_contain(childTwo);
                    };

                    it["child two node should see child one node"] = () =>
                    {
                        childTwo.Siblings().should_contain(childOne);
                    };
                };
            };
        }
Exemple #4
0
        public void DeepChildrenOrg()
        {
            Organization org1 = Organization.Create();

            org1.Code     = StringFactory.NewGuid();
            org1.Name     = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();
            Assert.IsNotNull(org1);

            Organization org2 = Organization.Create();

            org2.Code     = StringFactory.NewGuid();
            org2.Name     = "org-test-name";
            org2.FullName = "org-test-fullname";
            org2.Save();
            org1.AddChild(org2);

            Organization org3 = Organization.GetOrganization(org1.Code);

            Assert.IsNotNull(org3);
            Assert.IsNotNull(org3.DeepChildren.Where(de => de.Id == org1.Id).ToList());

            org1.Delete();
            org1.RemoveChild(org2);
            org2.Delete();
            org3.Delete();
        }
Exemple #5
0
        public void RemoveChild()
        {
            Organization org = Organization.Create();

            org.Code     = StringFactory.NewGuid();
            org.Name     = "org-test-name";
            org.FullName = "org-test-fullname";
            org.Save();

            Organization org1 = Organization.Create();

            org1.Code     = StringFactory.NewGuid();
            org1.Name     = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();

            org.AddChild(org1);

            Organization org2 = Organization.GetOrganization(org.Code);

            Assert.IsNotNull(org2.Children.FirstOrDefault(o => o.Code == org1.Code));

            org.RemoveChild(org1);

            Organization org4 = Organization.GetOrganization(org.Code);
            var          a    = org4.Children.Where(o => o.Code == org1.Code).ToList();

            Assert.AreEqual(0, a.Count);

            org.Delete();
            org1.Delete();
        }
Exemple #6
0
        public void AddChild()
        {
            Organization org = Organization.Create();

            org.Code     = StringFactory.NewGuid();
            org.Name     = "org-test-name";
            org.FullName = "org-test-fullname";
            org.Save();

            Organization org1 = Organization.Create();

            org1.Code     = StringFactory.NewGuid();
            org1.Name     = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();
            org.AddChild(org1);

            Organization org2 = Organization.GetOrganization(org.Code);

            Assert.IsNotNull(org2.Children.FirstOrDefault(o => o.Code == org1.Code));

            org.Delete();
            org1.Delete();
            org2.Delete();
        }
Exemple #7
0
        void when_adding_a_child()
        {
            context["when adding a child organization"] = () =>
            {
                before = () =>
                {
                    parent.AddChild(child);
                };

                it["should contain a child"] = () =>
                {
                    parent.Children.should_contain(child);
                };

                it["should add the parent to the child's parent collection"] = () =>
                {
                    child.Parents.should_contain(parent);
                };
            };
        }
Exemple #8
0
        public OrganizationView AddOrganizationChild(int id, string name, string description)
        {
            Organization organization = this._organizationRepository.FindBy(id);

            if (organization == null)
            {
                throw new EntityIsInvalidException <string>(organization.ToString());
            }

            Organization result = organization.AddChild(name, description);

            this._uow.Commit();
            return(result.ConvertToOrganizationView());
        }
 protected void save_Click(object sender, EventArgs e)
 {
     this.FillModel(this.Model);
     if (string.IsNullOrWhiteSpace(this.Model.Code))
     {
         this.PageEngine.ShowMessageBox("编码不合法");
         return;
     }
     if (string.IsNullOrWhiteSpace(this.Model.Name))
     {
         this.PageEngine.ShowMessageBox("名称不合法");
         return;
     }
     try
     {
         this.Model.Extensions = FillDictionary();
         //编辑存在的组织
         if (!string.IsNullOrWhiteSpace(Args["id"]))
         {
             this.Model.Save();
         }
         else
         {
             this.Model.Save();
             Organization parent = Organization.GetOrganizationById(Args["parentId"]);
             if (parent != null)
             {
                 parent.AddChild(this.Model);
             }
         }
         this.PageEngine.ReturnValue("");
         this.PageEngine.CloseWindow();
     }
     catch (Exception ex)
     {
         this.PageEngine.ShowMessageBox(ex.Message);
     }
 }