[Test()] 
 public void DeleteListOfPartyTypeTest() 

                                            {
                                                
 PartyTypeManager partyTypeManager = new PartyTypeManager(); 
            try

                                                {
                                                    var partyStatusTypes = new List <PartyStatusType>();
                                                    partyStatusTypes.Add(new PartyStatusType()
                {
                    Name = "Created", Description = ""
                });
                                                    var partyType               = partyTypeManager.Create("partyTypetest", "test", "party type test", partyStatusTypes);
                                                    var partyType2              = partyTypeManager.Create("partyTypetest2", "test2", "party type test2", partyStatusTypes);
                                                    var partyType1Id            = partyType.Id;
                                                    var partyType2Id            = partyType2.Id;
                                                    List <PartyType> partyTypes = new List <PartyType>();
                                                    partyTypes.Add(partyType);
                                                    partyTypes.Add(partyType2);
                                                    partyTypeManager.Delete(partyTypes);
                                                    var partyType1AfterDelete = partyTypeManager.PartyTypeRepository.Get(cc => cc.Id == partyType1Id).FirstOrDefault();
                                                    var partyType2AfterDelete = partyTypeManager.PartyTypeRepository.Get(cc => cc.Id == partyType2Id).FirstOrDefault();
                                                    partyType1AfterDelete.Should().BeNull();
                                                    partyType2AfterDelete.Should().BeNull();
                                                } 
 finally
            {
                                                    partyTypeManager.Dispose();
                                                } 

                                            }
Exemple #2
0
        public void TempPartyToPermanentTest()
        {
            PartyManager     partyManager     = new PartyManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var partyStatusTypes = new List <PartyStatusType>();

            partyStatusTypes.Add(new PartyStatusType()
            {
                Name = "Created", Description = ""
            });
            var partyTypeTest   = partyTypeManager.Create("partyTypeTitle", "", "", partyStatusTypes);
            var partyStatusType = partyTypeManager.GetStatusType(partyTypeTest, "Created");
            //create cstom attributes
            var partyCustomAttribute1 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "FirstName", "", "", "", isMain: true);
            var partyCustomAttribute2 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "LastName", "", "", "", isMain: true);
            var partyCustomAttribute3 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "Int", "Age", "", "", "");
            //create with CustomAttributeValues<Id,value>
            Dictionary <long, String> customAttributeValues = new Dictionary <long, string>();

            customAttributeValues.Add(partyCustomAttribute1.Id, "Masoud");
            customAttributeValues.Add(partyCustomAttribute2.Id, "Allahyari");
            customAttributeValues.Add(partyCustomAttribute3.Id, "31");
            var party = partyManager.Create(partyTypeTest, "description test", DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), customAttributeValues);

            party.IsTemp.Should().Be(true);
            partyManager.TempPartyToPermanent(party.Id);
            var party_ = partyManager.GetParty(party.Id);

            party_.IsTemp.Should().Be(false);
            partyManager.Delete(party);
            partyTypeManager.Delete(partyTypeTest);
        }
Exemple #3
0
        public void DeletePartyTest()
        {
            //Deleting single party is already tested in PartyCreation
            PartyManager     partyManager     = new PartyManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var partyStatusTypes = new List <PartyStatusType>();

            partyStatusTypes.Add(new PartyStatusType()
            {
                Name = "Created", Description = ""
            });

            var partyTypeTest   = partyTypeManager.Create("partyTypeTitle", "", "", partyStatusTypes);
            var partyStatusType = partyTypeManager.GetStatusType(partyTypeTest, "Created");
            var party1          = partyManager.Create(partyTypeTest, "alias", "description test", DateTime.Now.AddMonths(-1), DateTime.Now.AddMonths(1), partyStatusType);
            var party2          = partyManager.Create(partyTypeTest, "alias2", "description test2", DateTime.Now.AddMonths(-1), DateTime.Now.AddMonths(1), partyStatusType);
            List <Dlm.Entities.Party.Party> parties = new List <Dlm.Entities.Party.Party>();

            parties.Add(party1);
            parties.Add(party2);
            partyManager.Delete(parties);
            var party1AfterDelete = partyManager.PartyRepository.Get(party1.Id);
            var party2AfterDelete = partyManager.PartyRepository.Get(party2.Id);

            party1AfterDelete.Should().BeNull();
            party2AfterDelete.Should().BeNull();
            partyTypeManager.Delete(partyTypeTest);
        }
                                            [Test()] 
 public void DeleteListOfPartyCustomAttributeTest() 

                                            {
                                                
 PartyTypeManager partyTypeManager = new PartyTypeManager(); 
            try

                                                {
                                                    var partyStatusTypes = new List <PartyStatusType>();
                                                    partyStatusTypes.Add(new PartyStatusType()
                {
                    Name = "Created", Description = ""
                });
                                                    var partyType = partyTypeManager.Create("partyTypetest", "test", "party type test", partyStatusTypes);

                                                    var partyCustomAttr1 = partyTypeManager.CreatePartyCustomAttribute(partyType, "test", "name", "", "", "");
                                                    var partyCustomAttr2 = partyTypeManager.CreatePartyCustomAttribute(partyType, "test2", "name2", "", "", "");

                                                    //cleanup
                                                    var partyCustomAttr1Id = partyCustomAttr1.Id;
                                                    var partyCustomAttr2Id = partyCustomAttr2.Id;
                                                    List <PartyCustomAttribute> partyCustomAttributes = new List <PartyCustomAttribute>();
                                                    partyCustomAttributes.Add(partyCustomAttr1);
                                                    partyCustomAttributes.Add(partyCustomAttr2);
                                                    partyTypeManager.DeletePartyCustomAttribute(partyCustomAttributes);
                                                    partyTypeManager.Delete(partyType);

                                                    //check if it is deleted
                                                    var partyCustomAttr1AfterDelete = partyTypeManager.PartyTypeRepository.Query(cc => cc.Id == partyCustomAttr1Id).FirstOrDefault();
                                                    var partyCustomAttr2AfterDelete = partyTypeManager.PartyTypeRepository.Query(cc => cc.Id == partyCustomAttr2Id).FirstOrDefault();
                                                    partyCustomAttr1AfterDelete.Should().BeNull();
                                                    partyCustomAttr2AfterDelete.Should().BeNull();
                                                } 
 finally
            {
                                                    partyTypeManager.Dispose();
                                                } 

                                            }
                                            

        [Test()] 
 public void CreateCustomAttributeTest() 

                                            {
                                                
 PartyTypeManager partyTypeManager = new PartyTypeManager(); 
            try

                                                {
                                                    var partyStatusTypes = new List <PartyStatusType>();
                                                    partyStatusTypes.Add(new PartyStatusType()
                {
                    Name = "Created", Description = ""
                });
                                                    var  partyType   = partyTypeManager.Create("partyTypetest", "test", "party type test", partyStatusTypes);
                                                    long partyTypeId = partyType.Id;
                                                    partyType.Should().NotBeNull();
                                                    var  partyCustomAttribute   = partyTypeManager.CreatePartyCustomAttribute(partyType, "string", "Name", "nothing", "validVals", "noCondition", false, false, true);
                                                    long partyCustomAttributeId = partyCustomAttribute.Id;
                                                    partyCustomAttribute.Should().NotBeNull();
                                                    partyCustomAttribute.Id.Should().BeGreaterThan(0);
                                                    var fetchedPartyCustomAttribute = partyTypeManager.PartyCustomAttributeRepository.Get(partyCustomAttribute.Id);
                                                    partyCustomAttribute.Condition.Should().BeEquivalentTo(fetchedPartyCustomAttribute.Condition);
                                                    partyCustomAttribute.DataType.Should().BeEquivalentTo(fetchedPartyCustomAttribute.DataType);
                                                    partyCustomAttribute.DisplayName.Should().BeEquivalentTo(fetchedPartyCustomAttribute.DisplayName);
                                                    partyCustomAttribute.Description.Should().BeEquivalentTo(fetchedPartyCustomAttribute.Description);
                                                    partyCustomAttribute.DisplayOrder.Should().Equals(fetchedPartyCustomAttribute.DisplayOrder);
                                                    partyCustomAttribute.IsMain.Should().Equals(fetchedPartyCustomAttribute.IsMain);
                                                    partyCustomAttribute.IsUnique.Should().Equals(fetchedPartyCustomAttribute.IsUnique);
                                                    partyCustomAttribute.DisplayOrder.Should().Equals(fetchedPartyCustomAttribute.DisplayOrder);
                                                    partyTypeManager.DeletePartyCustomAttribute(partyCustomAttribute);// cleanup the DB
                var partyCustomAttributeAfterDelete = partyTypeManager.PartyCustomAttributeRepository.Get(cc => cc.Id == partyCustomAttributeId).FirstOrDefault();
                                                    partyCustomAttributeAfterDelete.Should().BeNull();
                                                    var objPartyCustomAttribute = new PartyCustomAttribute()
                                                    {
                                                        Condition   = "condition",
                                                        DataType    = "datatype",
                                                        Description = "description"
                                                        ,
                                                        DisplayName     = "displayname",
                                                        DisplayOrder    = 1,
                                                        IsMain          = false,
                                                        IsUnique        = false,
                                                        IsValueOptional = false,
                                                        Name            = "name",
                                                        PartyType       = partyType,
                                                        ValidValues     = "someVals"
                                                    };
                                                    var partyCustomAttributeFromObject        = partyTypeManager.CreatePartyCustomAttribute(objPartyCustomAttribute);
                                                    var fetchedPartyCustomAttributeFromObject = partyTypeManager.PartyCustomAttributeRepository.Get(partyCustomAttributeFromObject.Id);
                                                    partyCustomAttributeFromObject.Condition.Should().BeEquivalentTo(fetchedPartyCustomAttributeFromObject.Condition);
                                                    partyCustomAttributeFromObject.DataType.Should().BeEquivalentTo(fetchedPartyCustomAttributeFromObject.DataType);
                                                    partyCustomAttributeFromObject.DisplayName.Should().BeEquivalentTo(fetchedPartyCustomAttributeFromObject.DisplayName);
                                                    partyCustomAttributeFromObject.Description.Should().BeEquivalentTo(fetchedPartyCustomAttributeFromObject.Description);
                                                    partyCustomAttributeFromObject.DisplayOrder.Should().Equals(fetchedPartyCustomAttributeFromObject.DisplayOrder);
                                                    partyCustomAttributeFromObject.IsMain.Should().Equals(fetchedPartyCustomAttributeFromObject.IsMain);
                                                    partyCustomAttributeFromObject.IsUnique.Should().Equals(fetchedPartyCustomAttributeFromObject.IsUnique);
                                                    partyCustomAttributeFromObject.DisplayOrder.Should().Equals(fetchedPartyCustomAttributeFromObject.DisplayOrder);
                                                    partyTypeManager.DeletePartyCustomAttribute(partyCustomAttributeFromObject);// cleanup the DB
                partyTypeManager.Delete(partyType);// 
                var partyTypeAfterDelete = partyTypeManager.PartyTypeRepository.Get(cc => cc.Id == partyTypeId).FirstOrDefault();
                                                    partyTypeAfterDelete.Should().BeNull();
                                                } 
 finally
            {
                                                    partyTypeManager.Dispose();
                                                } 

                                            }
Exemple #6
0
        public void AddPartyRelationshipTest()
        {
            PartyManager     partyManager     = new PartyManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var partyStatusTypes = new List <PartyStatusType>();

            partyStatusTypes.Add(new PartyStatusType()
            {
                Name = "Created", Description = ""
            });
            var partyTypeTest   = partyTypeManager.Create("partyTypeTitle", "", "", partyStatusTypes);
            var partyTypeTest2  = partyTypeManager.Create("partyTypeTitle2", "", "", partyStatusTypes);
            var partyStatusType = partyTypeManager.GetStatusType(partyTypeTest, "Created");
            //create cstom attributes
            var partyCustomAttribute1 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "FirstName", "", "", "", isMain: true);
            var partyCustomAttribute2 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "LastName", "", "", "", isMain: true);
            var partyCustomAttribute3 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "Int", "Age", "", "", "");
            //create with CustomAttributeValues<Id,value>
            Dictionary <long, String> customAttributeValues = new Dictionary <long, string>();

            customAttributeValues.Add(partyCustomAttribute1.Id, "Masoud");
            customAttributeValues.Add(partyCustomAttribute2.Id, "Allahyari");
            customAttributeValues.Add(partyCustomAttribute3.Id, "31");
            var party = partyManager.Create(partyTypeTest2, "description test", DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), customAttributeValues);

            //create with CustomAttributeValues<Id,value>
            customAttributeValues = new Dictionary <long, string>();
            customAttributeValues.Add(partyCustomAttribute1.Id, "Ali");
            customAttributeValues.Add(partyCustomAttribute2.Id, "Wandern");
            customAttributeValues.Add(partyCustomAttribute3.Id, "37");
            var party2 = partyManager.Create(partyTypeTest, "description test", DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), customAttributeValues);

            //party type pair
            var prtManager = new PartyRelationshipTypeManager();

            prtManager.Create("relationship test", "", "", true, 10, 0, true, partyTypeTest, partyTypeTest2, "type pair test", "", "", "", 0);

            // partyManager.AddPartyRelationship(party,party2,"relation test","",)
            //add relationship

            //test maximun and minimum cardinality
        }
                                            public void UpdateCustomAttributeTest() 

                                            {
                                                
 PartyTypeManager partyTypeManager = new PartyTypeManager();

                                                try
                                                {
                                                    var partyStatusTypes = new List <PartyStatusType>();
                                                    partyStatusTypes.Add(new PartyStatusType()
                {
                    Name = "Created", Description = ""
                });
                                                    var partyType        = partyTypeManager.Create("partyTypetest", "test", "party type test", partyStatusTypes);
                                                    var partyType2       = partyTypeManager.Create("partyTypetest2", "test2", "party type test", partyStatusTypes);
                                                    var partyCustomAttr1 = partyTypeManager.CreatePartyCustomAttribute(partyType, "test", "name", "", "", "", false, true, true, 1);
                                                    partyCustomAttr1.DataType        = "test3";
                                                    partyCustomAttr1.Name            = "otherName";
                                                    partyCustomAttr1.Description     = "desc";
                                                    partyCustomAttr1.ValidValues     = "test3";
                                                    partyCustomAttr1.DisplayName     = "test 3";
                                                    partyCustomAttr1.DisplayOrder    = 2;
                                                    partyCustomAttr1.IsMain          = true;
                                                    partyCustomAttr1.IsUnique        = true;
                                                    partyCustomAttr1.IsValueOptional = false;
                                                    partyCustomAttr1.PartyType       = partyType2;
                                                    partyTypeManager.UpdatePartyCustomAttribute(partyCustomAttr1);
                                                    var updatedPartyCustomAttr = partyTypeManager.PartyCustomAttributeRepository.Get(partyCustomAttr1.Id);
                                                    partyCustomAttr1.Condition.Should().BeEquivalentTo(updatedPartyCustomAttr.Condition);
                                                    partyCustomAttr1.DataType.Should().BeEquivalentTo(updatedPartyCustomAttr.DataType);
                                                    partyCustomAttr1.DisplayName.Should().BeEquivalentTo(updatedPartyCustomAttr.DisplayName);
                                                    partyCustomAttr1.Description.Should().BeEquivalentTo(updatedPartyCustomAttr.Description);
                                                    partyCustomAttr1.DisplayOrder.Should().Equals(updatedPartyCustomAttr.DisplayOrder);
                                                    partyCustomAttr1.IsMain.Should().Equals(updatedPartyCustomAttr.IsMain);
                                                    partyCustomAttr1.IsUnique.Should().Equals(updatedPartyCustomAttr.IsUnique);
                                                    partyCustomAttr1.DisplayOrder.Should().Equals(updatedPartyCustomAttr.DisplayOrder);
                                                    partyTypeManager.DeletePartyCustomAttribute(updatedPartyCustomAttr);
                                                    partyTypeManager.Delete(partyType);
                                                }
                                                finally
                                                {
                                                    partyTypeManager.Dispose();
                                                }
                                            }
Exemple #8
0
        public void UpdatePartyTest()
        {
            //Deleting single party is already tested in PartyCreation
            PartyManager     partyManager     = new PartyManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var partyStatusTypes = new List <PartyStatusType>();

            partyStatusTypes.Add(new PartyStatusType()
            {
                Name = "Created", Description = ""
            });
            var partyTypeTest   = partyTypeManager.Create("partyTypeTitle", "", "", partyStatusTypes);
            var partyStatusType = partyTypeManager.GetStatusType(partyTypeTest, "Created");
            //create cstom attributes
            var partyCustomAttribute1 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "FirstName", "", "", "", isMain: true);
            var partyCustomAttribute2 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "LastName", "", "", "", isMain: true);
            var partyCustomAttribute3 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "Int", "Age", "", "", "");
            //create with CustomAttributeValues<Id,value>
            Dictionary <long, String> customAttributeValues = new Dictionary <long, string>();

            customAttributeValues.Add(partyCustomAttribute1.Id, "Masoud");
            customAttributeValues.Add(partyCustomAttribute2.Id, "Allahyari");
            customAttributeValues.Add(partyCustomAttribute3.Id, "31");
            var party        = partyManager.Create(partyTypeTest, "description test", DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), customAttributeValues);
            var updatedParty = partyManager.PartyRepository.Get(party.Id);

            updatedParty.Alias       = "alias2";
            updatedParty.Description = "desc";
            updatedParty.EndDate     = DateTime.Now.AddMonths(1);
            updatedParty.StartDate   = DateTime.Now.AddMonths(-1);
            partyManager.Update(updatedParty);
            var fetchedParty = partyManager.PartyRepository.Get(party.Id);

            //First name and lastname in custom attributes were defined as main;therefore, party name should be "name lastname"
            party.Name.Should().BeEquivalentTo("Masoud Allahyari");
            party.Alias.Should().BeEquivalentTo(fetchedParty.Alias);
            party.Description.Should().BeEquivalentTo(fetchedParty.Description);
            party.EndDate.ToShortDateString().Should().Be(fetchedParty.EndDate.ToShortDateString());
            party.PartyType.Id.Should().Be(fetchedParty.PartyType.Id);
            party.StartDate.ToShortDateString().Should().Be(fetchedParty.StartDate.ToShortDateString());
            party.Id.Should().Be(fetchedParty.Id);

            partyManager.Delete(party);
            partyTypeManager.Delete(partyTypeTest);
        }
                                            

        [Test()] 
 public void CreatePartyTypeTest() 

                                            {
                                                
 PartyTypeManager partyTypeManager = new PartyTypeManager(); 
            try

                                                {
                                                    var partyStatusTypes = new List <PartyStatusType>();
                                                    partyStatusTypes.Add(new PartyStatusType()
                {
                    Name = "Created", Description = ""
                });
                                                    var  partyType   = partyTypeManager.Create("partyTypetest", "test", "party type test", partyStatusTypes);
                                                    long partyTypeId = partyType.Id;
                                                    partyType.Should().NotBeNull();
                                                    partyType.Id.Should().BeGreaterThan(0);
                                                    var fetchedPartyType = partyTypeManager.PartyTypeRepository.Get(partyType.Id);
                                                    partyType.Title.Should().BeEquivalentTo(fetchedPartyType.Title);
                                                    partyType.DisplayName.Should().BeEquivalentTo(fetchedPartyType.DisplayName);
                                                    partyType.Description.Should().BeEquivalentTo(fetchedPartyType.Description);
                                                    partyTypeManager.Delete(partyType);// cleanup the DB
                var partyTypeAfterDelete = partyTypeManager.PartyTypeRepository.Get(cc => cc.Id == partyTypeId).FirstOrDefault();
                                                    partyTypeAfterDelete.Should().BeNull();
                                                } 
 finally
            {
                                                    partyTypeManager.Dispose();
                                                } 

                                            }
Exemple #10
0
        public void CreatePartyTest()
        {
            //Scenario: create, create with CustomAttributeValues<Id,value>, create with CustomAttributeValues<Name,value>,
            PartyManager     partyManager     = new PartyManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var partyStatusTypes = new List <PartyStatusType>();

            partyStatusTypes.Add(new PartyStatusType()
            {
                Name = "Created", Description = ""
            });

            var partyTypeTest   = partyTypeManager.Create("partyTypeTitle", "", "", partyStatusTypes);
            var partyStatusType = partyTypeManager.GetStatusType(partyTypeTest, "Created");
            var party1          = partyManager.Create(partyTypeTest, "alias", "description test", DateTime.Now.AddMonths(-1), DateTime.Now.AddMonths(1), partyStatusType);

            party1.Should().NotBeNull();
            party1.Id.Should().BeGreaterThan(0);
            var party1Id     = party1.Id;
            var fetchedParty = partyManager.PartyRepository.Get(party1Id);

            party1.Name.Should().BeEquivalentTo(fetchedParty.Name);
            party1.Alias.Should().BeEquivalentTo(fetchedParty.Alias);
            party1.Description.Should().BeEquivalentTo(fetchedParty.Description);
            party1.EndDate.ToShortDateString().Should().BeEquivalentTo(fetchedParty.EndDate.ToShortDateString());
            party1.PartyType.Id.Should().Be(fetchedParty.PartyType.Id);
            party1.StartDate.ToShortDateString().Should().BeEquivalentTo(fetchedParty.StartDate.ToShortDateString());
            party1.Id.Should().Be(fetchedParty.Id);
            //cleanup
            partyManager.Delete(party1);
            var partyAfterDelete = partyManager.PartyRepository.Get(cc => cc.Id == party1Id).FirstOrDefault();

            partyAfterDelete.Should().BeNull();
            //create cstom attributes
            var partyCustomAttribute1 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "FirstName", "", "", "", isMain: true);
            var partyCustomAttribute2 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "String", "LastName", "", "", "", isMain: true);
            var partyCustomAttribute3 = partyTypeManager.CreatePartyCustomAttribute(partyTypeTest, "Int", "Age", "", "", "");
            //create with CustomAttributeValues<Id,value>
            Dictionary <long, String> customAttributeValues = new Dictionary <long, string>();

            customAttributeValues.Add(partyCustomAttribute1.Id, "Masoud");
            customAttributeValues.Add(partyCustomAttribute2.Id, "Allahyari");
            customAttributeValues.Add(partyCustomAttribute3.Id, "31");
            var party2        = partyManager.Create(partyTypeTest, "", null, null, customAttributeValues);
            var party2Id      = party2.Id;
            var fetchedParty2 = partyManager.PartyRepository.Get(party2Id);

            //First name and lastname in custom attributes were defined as main;therefore, party name should be "name lastname"
            party2.Name.Should().BeEquivalentTo("Masoud Allahyari");
            party2.Alias.Should().BeEquivalentTo(fetchedParty2.Alias);
            party2.Description.Should().BeEquivalentTo(fetchedParty2.Description);
            party2.EndDate.ToShortDateString().Should().Be(fetchedParty2.EndDate.ToShortDateString());
            party2.PartyType.Id.Should().Be(fetchedParty2.PartyType.Id);
            party2.StartDate.ToShortDateString().Should().Be(fetchedParty2.StartDate.ToShortDateString());
            party2.Id.Should().Be(fetchedParty2.Id);
            var fethedCustomAttributeValues = fetchedParty2.CustomAttributeValues;

            fethedCustomAttributeValues.Count().Should().Be(customAttributeValues.Count());

            fethedCustomAttributeValues.Any(cc => cc.Value == "Masoud" && cc.CustomAttribute.Id == partyCustomAttribute1.Id).Should().Be(true);
            fethedCustomAttributeValues.Any(cc => cc.Value == "Allahyari" && cc.CustomAttribute.Id == partyCustomAttribute2.Id).Should().Be(true);
            fethedCustomAttributeValues.Any(cc => cc.Value == "31" && cc.CustomAttribute.Id == partyCustomAttribute3.Id).Should().Be(true);
            fethedCustomAttributeValues.Any(cc => cc.Value == "30" && cc.CustomAttribute.Id == partyCustomAttribute3.Id).Should().Be(false);
            //Cleanup DB
            partyManager.Delete(party2);
            //custom Attribute values should have benn deleted
            var customAttrValues = partyManager.PartyCustomAttributeValueRepository.Get(cc => cc.Party.Id == party2Id);

            customAttrValues.Count().Should().Be(0);
            //create with CustomAttributeValues<Name,value>
            Dictionary <String, String> customAttributeValues2 = new Dictionary <String, string>();

            customAttributeValues2.Add(partyCustomAttribute1.Name, "Alex");
            customAttributeValues2.Add(partyCustomAttribute2.Name, "Abedini");
            customAttributeValues2.Add(partyCustomAttribute3.Name, "31");
            var party3        = partyManager.Create(partyTypeTest, "", null, null, customAttributeValues2);
            var party3Id      = party3.Id;
            var fetchedParty3 = partyManager.PartyRepository.Get(party3Id);

            party3.Name.Should().BeEquivalentTo("Alex Abedini");
            party3.Alias.Should().BeEquivalentTo(fetchedParty3.Alias);
            party3.Description.Should().BeEquivalentTo(fetchedParty3.Description);
            party3.EndDate.ToShortDateString().Should().BeEquivalentTo(fetchedParty3.EndDate.ToShortDateString());
            party3.PartyType.Id.Should().Be(fetchedParty3.PartyType.Id);
            party3.StartDate.ToShortDateString().Should().BeEquivalentTo(fetchedParty3.StartDate.ToShortDateString());
            party3.Id.Should().Be(fetchedParty3.Id);
            fethedCustomAttributeValues = fetchedParty3.CustomAttributeValues;
            fethedCustomAttributeValues.Count().Should().Be(customAttributeValues2.Count());
            fethedCustomAttributeValues.Any(cc => cc.Value == "Alex" && cc.CustomAttribute.Id == partyCustomAttribute1.Id).Should().Be(true);
            fethedCustomAttributeValues.Any(cc => cc.Value == "Abedini" && cc.CustomAttribute.Id == partyCustomAttribute2.Id).Should().Be(true);
            fethedCustomAttributeValues.Any(cc => cc.Value == "31" && cc.CustomAttribute.Id == partyCustomAttribute3.Id).Should().Be(true);
            fethedCustomAttributeValues.Any(cc => cc.Value == "30" && cc.CustomAttribute.Id == partyCustomAttribute3.Id).Should().Be(false);
            //Cleanup DB
            partyManager.Delete(party3);
            partyTypeManager.Delete(partyTypeTest);
        }
        /// <summary>
        /// Update rules:
        /// Comparison for update is by the title of elements: title of elements are not editable
        /// if title of an element is changed because remove is forbiden here ,  it adds it as a new element and the old one will remain there
        ///
        /// </summary>
        private void ImportPartyTypes()
        {
            PartyTypeManager             partyTypeManager             = null;
            PartyManager                 partyManager                 = null;
            PartyRelationshipTypeManager partyRelationshipTypeManager = null;

            try
            {
                partyTypeManager             = new PartyTypeManager();
                partyManager                 = new PartyManager();
                partyRelationshipTypeManager = new PartyRelationshipTypeManager();
                var         filePath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("BAM"), "partyTypes.xml");
                XDocument   xDoc     = XDocument.Load(filePath);
                XmlDocument xmlDoc   = new XmlDocument();
                xmlDoc.Load(xDoc.CreateReader());
                var partyTypesNodeList = xmlDoc.SelectNodes("//PartyTypes");

                var deleteAbleAttr       = new List <PartyCustomAttribute>();
                var deleteAbleAttrValues = new List <PartyCustomAttributeValue>();

                if (partyTypesNodeList.Count > 0)
                {
                    foreach (XmlNode partyTypeNode in partyTypesNodeList[0].ChildNodes)
                    {
                        if (!(partyTypeNode is XmlElement))
                        {
                            continue;
                        }

                        //Convert xmAttributeCollection to list to skipt the case sensitive and null problems
                        var attributes = new List <XmlAttribute>();
                        foreach (XmlAttribute att in partyTypeNode.Attributes)
                        {
                            attributes.Add(att);
                        }
                        var title       = GetAttributeValue(attributes, "Name", true);
                        var displayName = GetAttributeValue(attributes, "DisplayName", false);
                        var systemType  = GetAttributeValue(attributes, "SystemType", true);
                        var partyType   = partyTypeManager.PartyTypeRepository.Get(item => item.Title == title).FirstOrDefault();
                        //If there is not such a party type
                        if (partyType == null)
                        {
                            var partyStatusTypes = new List <PartyStatusType>();
                            partyStatusTypes.Add(new PartyStatusType()
                            {
                                Name = "Created", Description = ""
                            });
                            partyType = partyTypeManager.Create(title, "Imported from partyTypes.xml", displayName, partyStatusTypes, (systemType == null ? false : Convert.ToBoolean(systemType)));
                            var customAttrs = new List <PartyCustomAttribute>();
                            foreach (XmlNode customAttrNode in partyTypeNode.ChildNodes)
                            {
                                if (!(customAttrNode is XmlElement))
                                {
                                    continue;
                                }

                                var customAttrNodeAttributes = new List <XmlAttribute>();
                                foreach (XmlAttribute att in customAttrNode.Attributes)
                                {
                                    customAttrNodeAttributes.Add(att);
                                }
                                PartyCustomAttribute partyCustomAttr = ParsePartyCustomAttribute(customAttrNodeAttributes);

                                customAttrs.Add(new PartyCustomAttribute()
                                {
                                    DataType        = partyCustomAttr.DataType,
                                    Description     = partyCustomAttr.Description,
                                    IsMain          = partyCustomAttr.IsMain,
                                    IsUnique        = partyCustomAttr.IsUnique,
                                    IsValueOptional = partyCustomAttr.IsValueOptional,
                                    Name            = partyCustomAttr.Name,
                                    PartyType       = partyType,
                                    ValidValues     = partyCustomAttr.ValidValues,
                                    DisplayName     = partyCustomAttr.DisplayName,
                                    Condition       = partyCustomAttr.Condition
                                });
                            }

                            if (!customAttrs.Any(c => c.IsMain))
                            {
                                customAttrs[0].IsMain = true;
                            }

                            foreach (var customAttr in customAttrs)
                            {
                                partyTypeManager.CreatePartyCustomAttribute(customAttr);
                            }
                        }
                        else //partytype exist
                        {
                            var newCustomAttrs      = new List <PartyCustomAttribute>();
                            var existingCustomAttrs = new List <PartyCustomAttribute>();

                            foreach (XmlNode customAttrNode in partyTypeNode.ChildNodes)
                            {
                                if (!(customAttrNode is XmlElement))
                                {
                                    continue;
                                }

                                var attributesList = new List <XmlAttribute>();
                                foreach (XmlAttribute att in customAttrNode.Attributes)
                                {
                                    attributesList.Add(att);
                                }

                                var customAttrName = GetAttributeValue(attributesList, "Name", true);
                                //create new custom attribute if there is not such a name
                                if (!partyType.CustomAttributes.Any(item => item.Name == customAttrName))
                                {
                                    var customAttrNodeAttributes = new List <XmlAttribute>();
                                    foreach (XmlAttribute att in customAttrNode.Attributes)
                                    {
                                        customAttrNodeAttributes.Add(att);
                                    }

                                    PartyCustomAttribute partyCustomAttr = ParsePartyCustomAttribute(customAttrNodeAttributes);
                                    newCustomAttrs.Add(new PartyCustomAttribute()
                                    {
                                        DataType        = partyCustomAttr.DataType,
                                        Description     = partyCustomAttr.Description,
                                        IsMain          = partyCustomAttr.IsMain,
                                        IsUnique        = partyCustomAttr.IsUnique,
                                        IsValueOptional = partyCustomAttr.IsValueOptional,
                                        Name            = customAttrName,
                                        PartyType       = partyType,
                                        ValidValues     = partyCustomAttr.ValidValues,
                                        DisplayName     = partyCustomAttr.DisplayName,
                                        Condition       = partyCustomAttr.Condition
                                    });
                                }
                                else //update if exist
                                {
                                    //add to existingCustomAttr list
                                    var existingAttr = partyType.CustomAttributes.Where(item => item.Name == customAttrName).FirstOrDefault();
                                    if (existingAttr != null)
                                    {
                                        existingCustomAttrs.Add(existingAttr);
                                    }
                                }
                            }// end foreach customAttrNode

                            if (!newCustomAttrs.Any(c => c.IsMain) && !partyType.CustomAttributes.Any(c => c.IsMain))
                            {
                                throw new Exception("There is no main field. Each party type needs at least one main field.");
                            }

                            // create all custom Attr´s
                            foreach (var customAttr in newCustomAttrs)
                            {
                                partyTypeManager.CreatePartyCustomAttribute(customAttr);
                            }

                            // Delete all attrs that are no longer in the partytype.xml
                            newCustomAttrs.AddRange(existingCustomAttrs);
                            var currentListOfAttr = partyType.CustomAttributes;

                            foreach (var attr in currentListOfAttr)
                            {
                                if (!newCustomAttrs.Any(a => a.Id.Equals(attr.Id)))
                                {
                                    deleteAbleAttr.Add(attr);
                                    //select all value that are created based on the attr
                                    // the values need to delete befor the attr itself
                                    deleteAbleAttrValues.AddRange(
                                        partyManager.PartyCustomAttributeValueRepository.Query()
                                        .Where(v => v.CustomAttribute.Id.Equals(attr.Id)));
                                }
                            }
                        }
                    }
                }
                var partyRelationshipTypesNodeList = xmlDoc.SelectNodes("//PartyRelationshipTypes");
                if (partyRelationshipTypesNodeList.Count > 0)
                {
                    foreach (XmlNode partyRelationshipTypesNode in partyRelationshipTypesNodeList[0].ChildNodes)
                    {
                        if (!(partyRelationshipTypesNode is XmlElement))
                        {
                            continue;
                        }

                        var customAttrNodeAttributes = new List <XmlAttribute>();
                        foreach (XmlAttribute att in partyRelationshipTypesNode.Attributes)
                        {
                            customAttrNodeAttributes.Add(att);
                        }

                        var title              = GetAttributeValue(customAttrNodeAttributes, "Name", true);
                        var displayName        = GetAttributeValue(customAttrNodeAttributes, "DisplayName", false);
                        var description        = GetAttributeValue(customAttrNodeAttributes, "Description", false);
                        var indicatesHierarchy = GetAttributeValue(customAttrNodeAttributes, "IndicatesHierarchy", true); // false;
                        var maxCardinality     = GetAttributeValue(customAttrNodeAttributes, "MaxCardinality", true);     // -1
                        var minCardinality     = GetAttributeValue(customAttrNodeAttributes, "MinCardinality", true);     // 0

                        //Import party type pairs
                        var partyTypePairs = new List <PartyTypePair>();
                        foreach (XmlNode partyTypesPairNode in partyRelationshipTypesNode.ChildNodes[0].ChildNodes)
                        {
                            var partyTypesPairNodeAttributes = new List <XmlAttribute>();
                            foreach (XmlAttribute att in partyTypesPairNode.Attributes)
                            {
                                partyTypesPairNodeAttributes.Add(att);
                            }
                            var allowedSourceTitle = GetAttributeValue(partyTypesPairNodeAttributes, "SourceType", true);
                            var allowedTargetTitle = GetAttributeValue(partyTypesPairNodeAttributes, "TargetType", true);
                            var allowedSource      = partyTypeManager.PartyTypeRepository.Get(item => item.Title.ToLower() == allowedSourceTitle.ToLower()).FirstOrDefault();
                            if (allowedSource == null)
                            {
                                throw new Exception("Error in importing party relationship types ! \r\n " + allowedSourceTitle + " is not a party type!!");
                            }
                            var allowedTarget = partyTypeManager.PartyTypeRepository.Get(item => item.Title.ToLower() == allowedTargetTitle.ToLower()).FirstOrDefault();
                            if (allowedTarget == null)
                            {
                                throw new Exception("Error in importing party relationship types ! \r\n " + allowedTargetTitle + " is not a party type!!");
                            }

                            var typePairTitle       = GetAttributeValue(partyTypesPairNodeAttributes, "Title", true);
                            var typePairDescription = GetAttributeValue(partyTypesPairNodeAttributes, "Description", false);
                            var typePairDefault     = GetAttributeValue(partyTypesPairNodeAttributes, "Default", true);
                            var conditionSource     = GetAttributeValue(partyTypesPairNodeAttributes, "conditionSource", false);
                            var conditionTarget     = GetAttributeValue(partyTypesPairNodeAttributes, "conditionTarget", false);
                            var permissionsTemplate = GetAttributeValue(partyTypesPairNodeAttributes, "permissionsTemplate", false);
                            partyTypePairs.Add(new PartyTypePair()
                            {
                                SourcePartyType = allowedSource,
                                TargetPartyType = allowedTarget,
                                Description     = typePairDescription,
                                Title           = typePairTitle,
                                PartyRelationShipTypeDefault = typePairDefault == null ? true : Convert.ToBoolean(typePairDefault),
                                ConditionSource    = conditionSource,
                                ConditionTarget    = conditionTarget,
                                PermissionTemplate = Helper.GetPermissionValue(permissionsTemplate)
                            });
                        }

                        var partyRelationshipType = partyRelationshipTypeManager.PartyRelationshipTypeRepository.Get(item => item.Title == title).FirstOrDefault();
                        //If there is not such a party relationship type
                        //It is mandatory to create at least one party type pair when we are creating a party type relation
                        //
                        if (partyRelationshipType == null)
                        {
                            partyRelationshipType = partyRelationshipTypeManager.Create(title, displayName, description, (indicatesHierarchy == null ? false : Convert.ToBoolean(indicatesHierarchy)), maxCardinality == null ? -1 : int.Parse(maxCardinality), minCardinality == null ? 0 : int.Parse(minCardinality), partyTypePairs.First().PartyRelationShipTypeDefault, partyTypePairs.First().SourcePartyType, partyTypePairs.First().TargetPartyType,
                                                                                        partyTypePairs.First().Title, partyTypePairs.First().Description, partyTypePairs.First().ConditionSource, partyTypePairs.First().ConditionTarget, partyTypePairs.First().PermissionTemplate);
                        }
                        else
                        {
                            partyRelationshipType = partyRelationshipTypeManager.Update(partyRelationshipType.Id, title, "", description, (indicatesHierarchy == null ? false : Convert.ToBoolean(indicatesHierarchy)), maxCardinality == null ? -1 : int.Parse(maxCardinality), minCardinality == null ? 0 : int.Parse(minCardinality));
                            UpdateOrCreatePartyTypePair(partyTypePairs.First(), partyRelationshipType, partyRelationshipTypeManager);
                        }
                        //If there are more than one partyTypepair exist
                        //if (partyTypePairs.Count() > 1)
                        foreach (var partyTypePair in partyTypePairs.Where(item => item != partyTypePairs.First()))
                        {
                            UpdateOrCreatePartyTypePair(partyTypePair, partyRelationshipType, partyRelationshipTypeManager);//
                        }
                    }
                }
                //Add all the custom Attribute names ao custom grid column of default user
                foreach (var partyType in partyTypeManager.PartyTypeRepository.Get(cc => !cc.SystemType))
                {
                    foreach (var partyCustomAttr in partyType.CustomAttributes)
                    {
                        partyManager.UpdateOrAddPartyGridCustomColumn(partyType, partyCustomAttr, null);
                    }
                    var partyRelationshipTypePairs = partyRelationshipTypeManager.PartyTypePairRepository.Get(cc => cc.SourcePartyType.Id == partyType.Id && !cc.TargetPartyType.SystemType);
                    foreach (var partyTypePair in partyRelationshipTypePairs)
                    {
                        partyManager.UpdateOrAddPartyGridCustomColumn(partyType, null, partyTypePair);
                    }
                }

                if (deleteAbleAttr.Any())
                {
                    //delete all existing PartyCustomAttrValues
                    deleteAbleAttrValues.ForEach(a => partyManager.RemovePartyCustomAttributeValue(a));

                    // Delete all GridColumns of the CustomAttribute
                    var listOfIds         = deleteAbleAttr.Select(d => d.Id);
                    var gridColumns       = partyManager.PartyCustomGridColumnsRepository.Get();
                    var listOfGridColumns = gridColumns.Where(c => c.CustomAttribute != null && listOfIds.Contains(c.CustomAttribute.Id)).ToList();

                    listOfGridColumns.ForEach(c => partyManager.RemovePartyGridCustomColumn(c.Id));

                    // add CustomAttribute Grid Columns
                    deleteAbleAttr.ForEach(a => partyTypeManager.DeletePartyCustomAttribute(a));
                }
            }
            catch (Exception ex)
            {
                LoggerFactory.LogCustom("SeedData Failed: " + ex.Message);
                throw;
            }
            finally
            {
                partyManager?.Dispose();
                partyTypeManager?.Dispose();
                partyRelationshipTypeManager?.Dispose();
            }
        }
Exemple #12
0
        /// <summary>
        /// Update rules:
        /// Comparison for update is by the title of elements: title of elements are not editable
        /// if title of an element is changed because remove is forbiden here ,  it adds it as a new element and the old one will remain there
        ///
        /// </summary>
        private void ImportPartyTypes()
        {
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var         filePath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("BAM"), "partyTypes.xml");
            XDocument   xDoc     = XDocument.Load(filePath);
            XmlDocument xmlDoc   = new XmlDocument();

            xmlDoc.Load(xDoc.CreateReader());
            var partyTypesNodeList = xmlDoc.SelectNodes("//PartyTypes");

            if (partyTypesNodeList.Count > 0)
            {
                foreach (XmlNode partyTypeNode in partyTypesNodeList[0].ChildNodes)
                {
                    //Convert xmAttributeCollection to list to skipt the case sensitive and null problems
                    var attributes = new List <XmlAttribute>();
                    foreach (XmlAttribute att in partyTypeNode.Attributes)
                    {
                        attributes.Add(att);
                    }
                    var title       = GetAttributeValue(attributes, "Name", true);
                    var displayName = GetAttributeValue(attributes, "DisplayName", false);
                    var partyType   = partyTypeManager.PartyTypeRepository.Get(item => item.Title == title).FirstOrDefault();
                    //If there is not such a party type
                    if (partyType == null)
                    {
                        var partyStatusTypes = new List <PartyStatusType>();
                        partyStatusTypes.Add(new PartyStatusType()
                        {
                            Name = "Created", Description = ""
                        });
                        partyType = partyTypeManager.Create(title, "Imported from partyTypes.xml", displayName, partyStatusTypes);
                        var customAttrs = new List <PartyCustomAttribute>();
                        foreach (XmlNode customAttrNode in partyTypeNode.ChildNodes)
                        {
                            var customAttrNodeAttributes = new List <XmlAttribute>();
                            foreach (XmlAttribute att in customAttrNode.Attributes)
                            {
                                customAttrNodeAttributes.Add(att);
                            }
                            PartyCustomAttribute partyCustomAttr = ParsePartyCustomAttribute(customAttrNodeAttributes);

                            customAttrs.Add(new PartyCustomAttribute()
                            {
                                DataType        = partyCustomAttr.DataType,
                                Description     = partyCustomAttr.Description,
                                IsMain          = partyCustomAttr.IsMain,
                                IsUnique        = partyCustomAttr.IsUnique,
                                IsValueOptional = partyCustomAttr.IsValueOptional,
                                Name            = partyCustomAttr.Name,
                                PartyType       = partyType,
                                ValidValues     = partyCustomAttr.ValidValues,
                                DisplayName     = partyCustomAttr.DisplayName,
                                Condition       = partyCustomAttr.Condition
                            });
                        }
                        if (!customAttrs.Any(c => c.IsMain))
                        {
                            customAttrs[0].IsMain = true;
                        }
                        foreach (var customAttr in customAttrs)
                        {
                            partyTypeManager.CreatePartyCustomAttribute(customAttr);
                        }
                    }
                    else
                    {
                        var customAttrs = new List <PartyCustomAttribute>();
                        foreach (XmlNode customAttrNode in partyTypeNode.ChildNodes)
                        {
                            var attributesList = new List <XmlAttribute>();
                            foreach (XmlAttribute att in customAttrNode.Attributes)
                            {
                                attributesList.Add(att);
                            }

                            var customAttrName = GetAttributeValue(attributesList, "Name", true);
                            //create new custom attribute if there is not such a name
                            if (!partyType.CustomAttributes.Any(item => item.Name == customAttrName))
                            {
                                var customAttrNodeAttributes = new List <XmlAttribute>();
                                foreach (XmlAttribute att in customAttrNode.Attributes)
                                {
                                    customAttrNodeAttributes.Add(att);
                                }

                                PartyCustomAttribute partyCustomAttr = ParsePartyCustomAttribute(customAttrNodeAttributes);
                                customAttrs.Add(new PartyCustomAttribute()
                                {
                                    DataType        = partyCustomAttr.DataType,
                                    Description     = partyCustomAttr.Description,
                                    IsMain          = partyCustomAttr.IsMain,
                                    IsUnique        = partyCustomAttr.IsUnique,
                                    IsValueOptional = partyCustomAttr.IsValueOptional,
                                    Name            = customAttrName,
                                    PartyType       = partyType,
                                    ValidValues     = partyCustomAttr.ValidValues,
                                    DisplayName     = partyCustomAttr.DisplayName,
                                    Condition       = partyCustomAttr.Condition
                                });
                            }
                        }
                        if (!customAttrs.Any(c => c.IsMain) && !partyType.CustomAttributes.Any(c => c.IsMain))
                        {
                            throw new Exception("There is no main field. Each party type needs at least one main field.");
                        }
                        foreach (var customAttr in customAttrs)
                        {
                            partyTypeManager.CreatePartyCustomAttribute(customAttr);
                        }
                    }
                }
            }
            var partyRelationshipTypesNodeList = xmlDoc.SelectNodes("//PartyRelationshipTypes");

            if (partyRelationshipTypesNodeList.Count > 0)
            {
                foreach (XmlNode partyRelationshipTypesNode in partyRelationshipTypesNodeList[0].ChildNodes)
                {
                    var customAttrNodeAttributes = new List <XmlAttribute>();
                    foreach (XmlAttribute att in partyRelationshipTypesNode.Attributes)
                    {
                        customAttrNodeAttributes.Add(att);
                    }
                    var partyRelationshipTypeManager = new PartyRelationshipTypeManager();
                    var title              = GetAttributeValue(customAttrNodeAttributes, "Name", true);
                    var displayName        = GetAttributeValue(customAttrNodeAttributes, "DisplayName", false);
                    var description        = GetAttributeValue(customAttrNodeAttributes, "Description", false);
                    var indicatesHierarchy = GetAttributeValue(customAttrNodeAttributes, "IndicatesHierarchy", true); // false;
                    var maxCardinality     = GetAttributeValue(customAttrNodeAttributes, "MaxCardinality", true);     // -1
                    var minCardinality     = GetAttributeValue(customAttrNodeAttributes, "MinCardinality", true);     // 0

                    //Import party type pairs
                    var partyTypePairs = new List <PartyTypePair>();
                    foreach (XmlNode partyTypesPairNode in partyRelationshipTypesNode.ChildNodes[0].ChildNodes)
                    {
                        var partyTypesPairNodeAttributes = new List <XmlAttribute>();
                        foreach (XmlAttribute att in partyTypesPairNode.Attributes)
                        {
                            partyTypesPairNodeAttributes.Add(att);
                        }
                        var allowedSourceTitle = GetAttributeValue(partyTypesPairNodeAttributes, "AllowedSource", true);
                        var allowedTargetTitle = GetAttributeValue(partyTypesPairNodeAttributes, "AllowedTarget", true);
                        var allowedSource      = partyTypeManager.PartyTypeRepository.Get(item => item.Title.ToLower() == allowedSourceTitle.ToLower()).FirstOrDefault();
                        if (allowedSource == null)
                        {
                            throw new Exception("Error in importing party relationship types ! \r\n " + allowedSourceTitle + " is not a party type!!");
                        }
                        var allowedTarget = partyTypeManager.PartyTypeRepository.Get(item => item.Title.ToLower() == allowedTargetTitle.ToLower()).FirstOrDefault();
                        if (allowedTarget == null)
                        {
                            throw new Exception("Error in importing party relationship types ! \r\n " + allowedTargetTitle + " is not a party type!!");
                        }

                        var typePairTitle       = GetAttributeValue(partyTypesPairNodeAttributes, "Title", true);
                        var typePairDescription = GetAttributeValue(partyTypesPairNodeAttributes, "Description", false);
                        var typePairDefault     = GetAttributeValue(partyTypesPairNodeAttributes, "Default", true);
                        var conditionSource     = GetAttributeValue(partyTypesPairNodeAttributes, "conditionSource", false);
                        var conditionTarget     = GetAttributeValue(partyTypesPairNodeAttributes, "conditionTarget", false);
                        partyTypePairs.Add(new PartyTypePair()
                        {
                            AllowedSource = allowedSource,
                            AllowedTarget = allowedTarget,
                            Description   = typePairDescription,
                            Title         = typePairTitle,
                            PartyRelationShipTypeDefault = typePairDefault == null ? true : Convert.ToBoolean(typePairDefault),
                            ConditionSource = conditionSource,
                            ConditionTarget = conditionTarget
                        });
                    }

                    var partyRelationshipType = partyRelationshipTypeManager.PartyRelationshipTypeRepository.Get(item => item.Title == title).FirstOrDefault();
                    //If there is not such a party relationship type
                    //It is mandatory to create at least one party type pair when we are creating a party type relation
                    //
                    if (partyRelationshipType == null)
                    {
                        partyRelationshipType = partyRelationshipTypeManager.Create(title, displayName, description, (indicatesHierarchy == null ? false : Convert.ToBoolean(indicatesHierarchy)), maxCardinality == null ? -1 : int.Parse(maxCardinality), minCardinality == null ? 0 : int.Parse(minCardinality), partyTypePairs.First().PartyRelationShipTypeDefault, partyTypePairs.First().AllowedSource, partyTypePairs.First().AllowedTarget,
                                                                                    partyTypePairs.First().Title, partyTypePairs.First().Description, partyTypePairs.First().ConditionSource, partyTypePairs.First().ConditionTarget);
                    }
                    else
                    {
                        partyRelationshipType = partyRelationshipTypeManager.Update(partyRelationshipType.Id, title, description, (indicatesHierarchy == null ? false : Convert.ToBoolean(indicatesHierarchy)), maxCardinality == null ? -1 : int.Parse(maxCardinality), minCardinality == null ? 0 : int.Parse(minCardinality));
                        UpdateOrCreatePartyTypePair(partyTypePairs.First(), partyRelationshipType, partyRelationshipTypeManager);
                    }
                    //If there are more than one partyTypepair exist
                    //if (partyTypePairs.Count() > 1)
                    foreach (var partyTypePair in partyTypePairs.Where(item => item != partyTypePairs.First()))
                    {
                        UpdateOrCreatePartyTypePair(partyTypePair, partyRelationshipType, partyRelationshipTypeManager);//
                    }
                }
            }
        }