Beispiel #1
0
        public ActionResult Create()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Create Part", this.Session.GetTenant());

            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var model = new PartyModel();
            model.PartyTypeList = partyTypeManager.Repo.Get().ToList();
            return View(model);
        }
Beispiel #2
0
        public Boolean CheckUniqeness(int partyTypeId, int partyId, string hash)
        {
            PartyManager partyManager = null;

            try
            {
                partyManager = new PartyManager();
                PartyType partyType = new PartyTypeManager().PartyTypeRepository.Get(partyTypeId);
                Party     party     = partyManager.PartyRepository.Get(partyId);
                return(partyManager.CheckUniqueness(partyManager.PartyRepository, partyType, hash, party));
            }
            finally { partyManager?.Dispose(); }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Id">PartyType Id</param>
        /// <returns></returns>
        public ActionResult LoadPartyCustomAttr(int id)
        {
            using (PartyManager partyManager = new PartyManager())
                using (UserManager userManager = new UserManager())
                    using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                    {
                        long partyId    = 0;
                        var  partyIdStr = HttpContext.Request.Params["partyId"];

                        ViewBag.userRegistration = HttpContext.Request.Params["userReg"];

                        if (long.TryParse(partyIdStr, out partyId) && partyId != 0)
                        {
                            ViewBag.customAttrValues = partyManager.PartyRepository.Get(partyId).CustomAttributeValues.ToList();

                            var userId   = partyManager.GetUserIdByParty(partyId);
                            var userTask = userManager.FindByIdAsync(userId);
                            userTask.Wait();
                            var user = userTask.Result;
                            if (user != null)
                            {
                                ViewBag.email = user.Email;
                            }
                        }
                        // if no user is linked assume it is the user registration
                        else
                        {
                            var userName = HttpContext.User.Identity.Name;
                            var userTask = userManager.FindByNameAsync(userName);
                            userTask.Wait();
                            var user = userTask.Result;

                            ViewBag.email = user.Email;
                        }

                        // Add attribute name for email
                        if (ConfigurationManager.AppSettings["usePersonEmailAttributeName"] == "true")
                        {
                            ViewBag.PersonEmailAttributeName = ConfigurationManager.AppSettings["PersonEmailAttributeName"];
                        }

                        var customAttrList = new List <PartyCustomAttribute>();

                        IEnumerable <PartyType> partyType = partyTypeManager.PartyTypeRepository.Get(item => item.Id == id);
                        if (partyType != null)
                        {
                            customAttrList = partyType.First().CustomAttributes.ToList();
                        }
                        return(PartialView("_customAttributesPartial", customAttrList));
                    }
        }
Beispiel #4
0
        public ActionResult CreateUserParty(Party party, Dictionary <string, string> partyCustomAttributeValues, List <PartyRelationship> partyRelationships)
        {
            using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                using (PartyManager partyManager = new PartyManager())
                    using (PartyRelationshipTypeManager partyRelationshipManager = new PartyRelationshipTypeManager())
                        using (UserManager userManager = new UserManager())
                            using (PartyRelationshipTypeManager partyRelationshipTypeManager = new PartyRelationshipTypeManager())
                            {
                                // check if
                                var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name);
                                userTask.Wait();
                                var user = userTask.Result;

                                //check if the party blongs to the user
                                //Bind party if there is already a user associated to this party
                                var partyuser = partyManager.GetPartyByUser(user.Id);
                                if (partyuser == null)
                                {
                                    var partyType       = partyTypeManager.PartyTypeRepository.Get(party.PartyType.Id);
                                    var partyStatusType = partyTypeManager.GetStatusType(partyType, "Created");
                                    //Create party
                                    party = partyManager.Create(partyType, party.Description, null, null, partyCustomAttributeValues.ToDictionary(cc => long.Parse(cc.Key), cc => cc.Value));
                                    if (partyRelationships != null)
                                    {
                                        foreach (var partyRelationship in partyRelationships)
                                        {
                                            //the duration is from current datetime up to the end of target party date
                                            var TargetParty = partyManager.PartyRepository.Get(partyRelationship.TargetParty.Id);
                                            // var partyRelationshipType = partyRelationshipManager.PartyRelationshipTypeRepository.Get(partyRelationship.PartyRelationshipType.Id);
                                            var partyTypePair = partyRelationshipManager.PartyTypePairRepository.Get(partyRelationship.PartyTypePair.Id);
                                            partyManager.AddPartyRelationship(party, TargetParty, partyRelationship.Title, partyRelationship.Description, partyTypePair, DateTime.Now, TargetParty.EndDate, partyRelationship.Scope);
                                        }
                                    }

                                    partyManager.AddPartyUser(party, user.Id);

                                    //set FullName in user
                                    var    p           = partyManager.GetParty(party.Id);
                                    string displayName = String.Join(" ",
                                                                     p.CustomAttributeValues.
                                                                     Where(ca => ca.CustomAttribute.IsMain.Equals(true)).
                                                                     OrderBy(ca => ca.CustomAttribute.Id).
                                                                     Select(ca => ca.Value).ToArray());

                                    user.DisplayName = displayName;
                                    userManager.UpdateAsync(user);
                                }

                                return(RedirectToAction("Index"));
                            }
        }
Beispiel #5
0
 public ActionResult AddSystemSampleParties()
 {
     using (PartyTypeManager partyTypeManager = new PartyTypeManager())
     {
         //Example for adding system parties
         var customAttrs = new Dictionary <string, string>();
         customAttrs.Add("Name", "test dataset");
         Helper.CreateParty(DateTime.MinValue, DateTime.MaxValue, "", partyTypeManager.PartyTypeRepository.Get(cc => cc.Title == "Dataset").First().Id, customAttrs);
         customAttrs = new Dictionary <string, string>();
         customAttrs.Add("Name", "test group");
         Helper.CreateParty(DateTime.MinValue, DateTime.MaxValue, "", partyTypeManager.PartyTypeRepository.Get(cc => cc.Title == "Group").First().Id, customAttrs);
         return(RedirectToAction("Index"));
     }
 }
Beispiel #6
0
        public ActionResult Create(PartyModel partyModel, Dictionary<string, string> partyCustomAttributeValues)
        {
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            PartyManager partyManager = new PartyManager();
            validateAttribute(partyModel);
            if (partyModel.Errors.Count > 0)
                return View(partyModel);
            //
            var partyType = partyTypeManager.Repo.Get(partyModel.Party.PartyType.Id);
            var partyStatusType = partyTypeManager.GetStatusType(partyType, "Create");

            //Create party
            var party = partyManager.Create(partyType, partyModel.Party.Name, "", "", partyModel.Party.StartDate, partyModel.Party.EndDate, partyStatusType);
            //Add customAttriuteValue to party
            partyManager.AddPartyCustomAttriuteValue(party, ConvertDictionaryToPartyCustomeAttrValuesDictionary(partyCustomAttributeValues));
            return RedirectToAction("Index");
        }
Beispiel #7
0
        public ActionResult CreateEdit(int id, bool relationTabAsDefault = false)
        {
            PartyManager     partyManager     = null;
            PartyTypeManager partyTypeManager = null;

            try
            {
                partyManager     = new PartyManager();
                partyTypeManager = new PartyTypeManager();
                ViewBag.Title    = PresentationModel.GetGenericViewTitle("Edit Party");
                var model = new PartyModel();
                model.PartyTypeList      = partyTypeManager.PartyTypeRepository.Get(cc => !cc.SystemType).ToList();
                model.PartyRelationships = getPartyRelationships(id);
                Party party = partyManager.PartyRepository.Get(id);
                model.Description = party.Description;
                model.Id          = party.Id;
                model.PartyType   = party.PartyType;
                model.Name        = party.Name;
                //Set dates to null to not showing the minimum and maximum dates in UI
                if (party.StartDate == DateTime.MinValue)
                {
                    model.StartDate = null;
                }
                else
                {
                    model.StartDate = party.StartDate;
                }
                if (party.EndDate.Date == DateTime.MaxValue.Date)
                {
                    model.EndDate = null;
                }
                else
                {
                    model.EndDate = party.EndDate;
                }
                ViewBag.RelationTabAsDefault = relationTabAsDefault;
                ViewBag.Title = "Edit party";
                return(View("CreateEdit", model));
            }
            finally
            {
                partyManager?.Dispose();
                partyTypeManager?.Dispose();
            }
        }
Beispiel #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);
        }
Beispiel #9
0
        public ActionResult CreateUserParty(Party party, Dictionary <string, string> partyCustomAttributeValues, List <PartyRelationship> partyRelationships)
        {
            PartyTypeManager             partyTypeManager         = null;
            PartyManager                 partyManager             = null;
            PartyRelationshipTypeManager partyRelationshipManager = null;
            UserManager userManager = null;

            try
            {
                //check if the party blongs to the user
                //Bind party if there is already a user associated to this party

                userManager              = new UserManager();
                partyTypeManager         = new PartyTypeManager();
                partyManager             = new PartyManager();
                partyRelationshipManager = new PartyRelationshipTypeManager();
                var partyType       = partyTypeManager.PartyTypeRepository.Get(party.PartyType.Id);
                var partyStatusType = partyTypeManager.GetStatusType(partyType, "Created");
                //Create party
                party = partyManager.Create(partyType, party.Description, null, null, partyCustomAttributeValues.ToDictionary(cc => long.Parse(cc.Key), cc => cc.Value));
                if (partyRelationships != null)
                {
                    foreach (var partyRelationship in partyRelationships)
                    {
                        //the duration is from current datetime up to the end of target party date
                        var secondParty           = partyManager.PartyRepository.Get(partyRelationship.SecondParty.Id);
                        var partyRelationshipType = partyRelationshipManager.PartyRelationshipTypeRepository.Get(partyRelationship.PartyRelationshipType.Id);
                        var partyTypePair         = partyRelationshipManager.PartyTypePairRepository.Get(partyRelationship.PartyTypePair.Id);
                        partyManager.AddPartyRelationship(party, secondParty, partyRelationshipType, partyRelationship.Title, partyRelationship.Description, partyTypePair, DateTime.Now, secondParty.EndDate, partyRelationship.Scope);
                    }
                }
                var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name);
                userTask.Wait();
                var user = userTask.Result;
                partyManager.AddPartyUser(party, user.Id);
                return(RedirectToAction("Index"));
            }
            finally
            {
                partyTypeManager?.Dispose();
                partyManager?.Dispose();
                partyRelationshipManager?.Dispose();
            }
        }
Beispiel #10
0
        public ActionResult View(int id)
        {
            PartyManager     partyManager     = null;
            PartyTypeManager partyTypeManager = null;

            try
            {
                partyManager     = new PartyManager();
                partyTypeManager = new PartyTypeManager();
                ViewBag.Title    = PresentationModel.GetGenericViewTitle("View Party");
                var model = new PartyModel();
                model.PartyTypeList      = partyTypeManager.PartyTypeRepository.Get().ToList();
                model.PartyRelationships = getPartyRelationships(id);
                Party party = partyManager.PartyRepository.Get(id);
                model.Description = party.Description;
                model.PartyType   = party.PartyType;
                model.Id          = party.Id;
                model.Name        = party.Name;
                if (party.StartDate == DateTime.MinValue)
                {
                    model.StartDate = null;
                }
                else
                {
                    model.StartDate = party.StartDate;
                }
                if (party.EndDate.Date == DateTime.MaxValue.Date)
                {
                    model.EndDate = null;
                }
                else
                {
                    model.EndDate = party.EndDate;
                }
                ViewBag.Title = "View party";
                return(View(model));
            }
            finally
            {
                partyManager?.Dispose();
                partyTypeManager?.Dispose();
            }
        }
Beispiel #11
0
        public ActionResult Create()
        {
            PartyTypeManager partyTypeManager = null;

            try
            {
                partyTypeManager = new PartyTypeManager();
                ViewBag.Title    = PresentationModel.GetGenericViewTitle("Create Party");
                var model = new PartyModel();
                model.PartyTypeList          = partyTypeManager.PartyTypeRepository.Get().ToList();
                ViewBag.RelationTabAsDefault = false;
                ViewBag.Title = "Create party";
                return(View("CreateEdit", model));
            }
            finally
            {
                partyTypeManager?.Dispose();
            }
        }
Beispiel #12
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();
                                                }
                                            }
Beispiel #14
0
        public ActionResult ViewPartyDetail(int id)
        {
            using (PartyManager partyManager = new PartyManager())
                using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                {
                    ViewBag.Title = PresentationModel.GetGenericViewTitle("View Party");
                    var model = new PartyModel();
                    model.PartyTypeList      = partyTypeManager.PartyTypeRepository.Get().ToList();
                    model.PartyRelationships = getPartyRelationships(id);

                    Party party = partyManager.PartyRepository.Get(id);
                    model.Description = party.Description;
                    model.EndDate     = party.EndDate;
                    model.Id          = party.Id;
                    model.PartyType   = party.PartyType;
                    model.StartDate   = party.StartDate;
                    model.ViewMode    = true;
                    model.Name        = party.Name;
                    return(PartialView("View", model));
                }
        }
Beispiel #15
0
        internal static Party CreateParty(PartyModel partyModel, Dictionary <string, string> partyCustomAttributeValues)
        {
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            PartyManager     partyManager     = new PartyManager();
            var party = new Party();

            try
            {
                PartyType partyType       = partyTypeManager.PartyTypeRepository.Get(partyModel.PartyType.Id);
                var       partyStatusType = partyTypeManager.GetStatusType(partyType, "Created");
                // save party as temp if the reationships are required
                var requiredPartyRelationTypes = new PartyRelationshipTypeManager().GetAllPartyRelationshipTypes(partyType.Id).Where(cc => cc.MinCardinality > 0);
                //Create party
                party = partyManager.Create(partyType, "", partyModel.Description, partyModel.StartDate, partyModel.EndDate, partyStatusType, requiredPartyRelationTypes.Any());
                partyManager.AddPartyCustomAttributeValues(party, partyCustomAttributeValues.ToDictionary(cc => long.Parse(cc.Key), cc => cc.Value));
            }
            finally
            {
                partyTypeManager?.Dispose();
                partyManager?.Dispose();
            }
            return(party);
        }
Beispiel #16
0
 public ActionResult LoadCustomGridColumns(string partyTypeTitle)
 {
     using (PartyManager partyManager = new PartyManager())
         using (PartyTypeManager partyTypeManager = new PartyTypeManager())
         {
             var partyType = partyTypeManager.PartyTypeRepository.Get(cc => cc.Title.Equals(partyTypeTitle)).FirstOrDefault();
             var partyCustomGridColumns = partyManager.GetPartyCustomGridColumns(partyType.Id, all: true);
             //To avoid NHibernate.LazyInitializationException in view
             //Todo: Finding a good soloution
             foreach (var partyCustomGridColumn in partyCustomGridColumns)
             {
                 if (partyCustomGridColumn.CustomAttribute != null)
                 {
                     partyCustomGridColumn.CustomAttribute.DisplayName = partyCustomGridColumn.CustomAttribute.DisplayName;
                 }
                 else
                 {
                     partyCustomGridColumn.TypePair.Title = partyCustomGridColumn.TypePair.Title;
                 }
             }
             return(PartialView("_partyGridFields", partyCustomGridColumns.ToList()));
         }
 }
Beispiel #17
0
 public ActionResult Edit(PartyModel partyModel, Dictionary<string, string> partyCustomAttributeValues)
 {
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         PartyTypeManager partyTypeManager = new PartyTypeManager();
         PartyManager partyManager = new PartyManager();
         validateAttribute(partyModel);
         if (partyModel.Errors.Count > 0)
             return View(partyModel);
         var party = partyManager.Repo.Reload(partyModel.Party);
         //Update some fields
         party.Description = partyModel.Party.Description;
         party.StartDate = partyModel.Party.StartDate;
         party.EndDate = partyModel.Party.EndDate;
         party.Name = partyModel.Party.Name;
         party = partyManager.Update(party);
         foreach (var partyCustomAttributeValueString in partyCustomAttributeValues)
         {
             var partyCustomAttribute = partyTypeManager.RepoPartyCustomAttribute.Get(int.Parse(partyCustomAttributeValueString.Key));
             partyManager.UpdatePartyCustomAttriuteValue(partyCustomAttribute, partyModel.Party, partyCustomAttributeValueString.Value);
         }
     }
     return RedirectToAction("Index");
 }
                                            

        [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();
                                                } 

                                            }
Beispiel #19
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);
        }
Beispiel #20
0
        public ActionResult ViewPartyDetail(int id)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("View Party", this.Session.GetTenant());

            PartyManager partyManager = new PartyManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            var model = new PartyModel();
            model.PartyTypeList = partyTypeManager.Repo.Get().ToList();
            model.Party = partyManager.Repo.Get(id);
            return PartialView("View", model);
        }
Beispiel #21
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="Id">PartyType Id</param>
 /// <returns></returns>
 public ActionResult LoadPartyCustomAttr(int id)
 {
     long partyId = 0;
     var partyIdStr = HttpContext.Request.Params["partyId"];
     if (long.TryParse(partyIdStr, out partyId))
     {
         PartyManager pm = new PartyManager();
         ViewBag.customAttrValues = pm.Repo.Get(partyId).CustomAttributeValues.ToList();
     }
     var customAttrList = new List<PartyCustomAttribute>();
     PartyTypeManager partyTypeManager = new PartyTypeManager();
     var partyType = partyTypeManager.Repo.Get(item => item.Id == id);
     if (partyType != null)
         customAttrList = partyType.First().CustomAttributes.ToList();
     return PartialView("_customAttributesView", customAttrList);
 }
Beispiel #22
0
        /// <summary>
        /// get all values from systen parties values
        ///
        /// </summary>
        /// <param name="mappings"></param>
        /// <returns></returns>
        private static List <MappingPartyResultElemenet> getAllValuesFromSystem(IEnumerable <Entities.Mapping.Mapping> mappings, string value)
        {
            using (MappingManager _mappingManager = new MappingManager())
                using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                    using (PartyManager partyManager = new PartyManager())
                    {
                        List <MappingPartyResultElemenet> tmp = new List <MappingPartyResultElemenet>();

                        IEnumerable <long> parentIds = mappings.Where(m => m.Parent != null).Select(m => m.Parent.Id).Distinct();

                        IEnumerable <Entities.Mapping.Mapping> selectedMappings;

                        // all Masks are the same
                        string       mask      = "";
                        PartyType    partyType = null;
                        List <Party> parties   = null;

                        foreach (var pId in parentIds)
                        {
                            Entities.Mapping.Mapping parentMapping = _mappingManager.GetMapping(pId);

                            selectedMappings =
                                mappings.Where(m => m.Parent != null && m.Parent.Id.Equals(pId));

                            long parentTypeId = parentMapping.Source.ElementId;
                            long sourceId     = selectedMappings.FirstOrDefault().Source.ElementId;

                            //mappings.FirstOrDefault().TransformationRule.Mask;

                            if (parentTypeId == 0)
                            {
                                partyType =
                                    partyTypeManager.PartyTypeRepository.Query()
                                    .FirstOrDefault(p => p.CustomAttributes.Any(c => c.Id.Equals(sourceId)));
                                parties = partyManager.PartyRepository.Query().Where(p => p.PartyType.Equals(partyType)).ToList();
                            }
                            else
                            {
                                partyType = partyTypeManager.PartyTypeRepository.Get(parentTypeId);
                                parties   = partyManager.PartyRepository.Query().Where(p => p.PartyType.Id.Equals(parentTypeId)).ToList();
                            }

                            //get all mapped element ids
                            var elementIds = mappings.Select(m => m.Source.ElementId);
                            // get all attributes based on the element id list
                            var attributeValues = partyManager.PartyCustomAttributeValueRepository.Query(y => elementIds.Contains(y.CustomAttribute.Id)).ToList();
                            attributeValues = attributeValues.Where(y => y.Value.ToLower().Contains(value.ToLower())).ToList();
                            //get all party ids
                            var partyIds = attributeValues.Select(a => a.Party.Id).Distinct();

                            foreach (var partyId in partyIds)
                            {
                                MappingPartyResultElemenet resultObject = new MappingPartyResultElemenet();
                                resultObject.PartyId = partyId;

                                //get mask from first mapping
                                mask = mappings.FirstOrDefault().TransformationRule.Mask;

                                var allMappedAttrValues = partyManager.PartyCustomAttributeValueRepository.Query(y =>
                                                                                                                 y.Party.Id.Equals(partyId) && elementIds.Contains(y.CustomAttribute.Id)).ToList();

                                foreach (var attrValue in allMappedAttrValues)
                                {
                                    //get mapping for the attrvalue
                                    var mapping = mappings.Where(m => m.Source.ElementId.Equals(attrValue.CustomAttribute.Id)).FirstOrDefault();

                                    List <string> regExResultList = transform(attrValue.Value, mapping.TransformationRule);
                                    string        placeHolderName = attrValue.CustomAttribute.Name;

                                    mask = setOrReplace(mask, regExResultList, placeHolderName);

                                    resultObject.Value = mask;
                                }

                                if (mask.ToLower().Contains(value.ToLower()))
                                {
                                    tmp.Add(resultObject);
                                }
                            }
                        }

                        return(tmp);
                    }
        }
Beispiel #23
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             = 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();
            }
        }
Beispiel #24
0
        public ActionResult Edit(PartyModel partyModel, Dictionary <string, string> partyCustomAttributeValues)
        {
            var party = new Party();

            using (PartyManager partyManager = new PartyManager())
                using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                    using (UserManager userManager = new UserManager())
                    {
                        if (!HttpContext.User.Identity.IsAuthenticated)
                        {
                            return(RedirectToAction("Index", "Home"));
                        }

                        var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name);
                        userTask.Wait();
                        var user      = userTask.Result;
                        var userParty = partyManager.GetPartyByUser(user.Id);
                        if (userParty.Id != partyModel.Id)
                        {
                            throw new Exception("Permission denied.");
                        }
                        if (partyModel.Id == 0)
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            party = Helpers.Helper.EditParty(partyModel, partyCustomAttributeValues, null);

                            var    p           = partyManager.GetParty(party.Id);
                            string displayName = String.Join(" ",
                                                             p.CustomAttributeValues.
                                                             Where(ca => ca.CustomAttribute.IsMain.Equals(true)).
                                                             OrderBy(ca => ca.CustomAttribute.Id).
                                                             Select(ca => ca.Value).ToArray());

                            user.DisplayName = displayName;

                            if (ConfigurationManager.AppSettings["usePersonEmailAttributeName"] == "true")
                            {
                                var nameProp = partyTypeManager.PartyCustomAttributeRepository.Get(attr => (attr.PartyType == party.PartyType) && (attr.Name == ConfigurationManager.AppSettings["PersonEmailAttributeName"])).FirstOrDefault();
                                if (nameProp != null)
                                {
                                    var entity = party.CustomAttributeValues.FirstOrDefault(item => item.CustomAttribute.Id == nameProp.Id);
                                    if (user.Email != entity.Value)
                                    {
                                        var es = new EmailService();
                                        es.Send(MessageHelper.GetUpdateEmailHeader(),
                                                MessageHelper.GetUpdaterEmailMessage(user.DisplayName, user.Email, entity.Value),
                                                ConfigurationManager.AppSettings["SystemEmail"]
                                                );
                                    }
                                    user.Email = entity.Value;
                                }
                            }


                            userManager.UpdateAsync(user);
                        }
                        return(RedirectToAction("Index", "Home", new { area = "" }));
                    }
        }
Beispiel #25
0
        public ActionResult UserRegistration()
        {
            PartyManager                 partyManager                 = null;
            PartyTypeManager             partyTypeManager             = null;
            PartyRelationshipTypeManager partyRelationshipTypeManager = null;
            UserManager userManager = null;

            try
            {
                if (!HttpContext.User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                //Defined AccountPartyTypes vallue in web config format is like PartyType1:PartyTypePairTitle1-PartyTypePairTitle2,PartyType2
                var accountPartyTypes     = new List <string>();
                var partyTypeAccountModel = new PartyTypeAccountModel();
                partyManager                 = new PartyManager();
                partyTypeManager             = new PartyTypeManager();
                partyRelationshipTypeManager = new PartyRelationshipTypeManager();
                userManager = new UserManager();
                var allowedAccountPartyTypes = GetPartyTypesForAccount();
                if (allowedAccountPartyTypes == null)
                {
                    throw new Exception("Allowed party types for registration in setting.xml are not exist!");
                }
                //Split them by "," and split each one by ":"
                foreach (var allowedAccountPartyType in allowedAccountPartyTypes)
                {
                    var partyType = partyTypeManager.PartyTypeRepository.Get(item => item.Title == allowedAccountPartyType.Key).FirstOrDefault();
                    if (partyType == null)
                    {
                        throw new Exception("AccountPartyType format in app setting is not correct or this 'partyType' doesn't exist.");
                    }
                    var allowedPartyTypePairs = new Dictionary <string, PartyTypePair>();
                    if (allowedAccountPartyType.Value != null)
                    {
                        var partyRelationshipsType = partyRelationshipTypeManager.PartyRelationshipTypeRepository.Get(item => allowedAccountPartyType.Value.Contains(item.Title));
                        foreach (var partyRelationshipType in partyRelationshipsType)
                        {
                            //filter AssociatedPairs to allowed pairs
                            partyRelationshipType.AssociatedPairs = partyRelationshipType.AssociatedPairs.Where(item => partyType.Id == item.SourcePartyType.Id && item.TargetPartyType.Parties.Any()).ToList();
                            //try to find first type pair which has PartyRelationShipTypeDefault otherwise the first one
                            var defaultPartyTypePair = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.PartyRelationShipTypeDefault);

                            if (defaultPartyTypePair == null)
                            {
                                defaultPartyTypePair = partyRelationshipType.AssociatedPairs.FirstOrDefault();
                            }
                            if (defaultPartyTypePair != null)
                            {
                                if (defaultPartyTypePair.TargetPartyType.Parties != null)
                                {
                                    defaultPartyTypePair.TargetPartyType.Parties = defaultPartyTypePair.TargetPartyType.Parties.OrderBy(item => item.Name).ToList(); // order parties by name
                                }
                                allowedPartyTypePairs.Add(partyRelationshipType.DisplayName, defaultPartyTypePair);
                            }
                        }
                    }
                    partyTypeAccountModel.PartyRelationshipsTypes.Add(partyType, allowedPartyTypePairs);
                }
                //Bind party if there is already a user associated to this party
                var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name);
                userTask.Wait();
                var user = userTask.Result;
                partyTypeAccountModel.Party = partyManager.GetPartyByUser(user.Id);
                //TODO: Discuss . Current soloution is to navigate the user to edit party
                if (partyTypeAccountModel.Party != null)
                {
                    return(RedirectToAction("Edit"));
                }
                return(View("_userRegisterationPartial", partyTypeAccountModel));
            }
            finally
            {
                partyManager?.Dispose();
                partyTypeManager?.Dispose();
                partyRelationshipTypeManager?.Dispose();
                userManager?.Dispose();
            }
        }
Beispiel #26
0
        /// <summary>
        /// get all values from systen parties values
        ///
        /// </summary>
        /// <param name="mappings"></param>
        /// <returns></returns>
        private static List <string> getAllValuesFromSystem(IEnumerable <Entities.Mapping.Mapping> mappings, string value)
        {
            MappingManager   _mappingManager  = new MappingManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            PartyManager     partyManager     = new PartyManager();

            List <string> tmp = new List <string>();

            IEnumerable <long> parentIds = mappings.Where(m => m.Parent != null).Select(m => m.Parent.Id).Distinct();

            IEnumerable <Entities.Mapping.Mapping> selectedMappings;

            // all Masks are the same
            string       mask      = "";
            PartyType    partyType = null;
            List <Party> parties   = null;

            foreach (var pId in parentIds)
            {
                Entities.Mapping.Mapping parentMapping = _mappingManager.GetMapping(pId);

                selectedMappings =
                    mappings.Where(m => m.Parent != null && m.Parent.Id.Equals(pId));


                long parentTypeId = parentMapping.Source.ElementId;
                long sourceId     = selectedMappings.FirstOrDefault().Source.ElementId;

                //mappings.FirstOrDefault().TransformationRule.Mask;

                if (parentTypeId == 0)
                {
                    partyType =
                        partyTypeManager.PartyTypeRepository.Query()
                        .FirstOrDefault(p => p.CustomAttributes.Any(c => c.Id.Equals(sourceId)));
                    parties = partyManager.PartyRepository.Get().Where(p => p.PartyType.Equals(partyType)).ToList();
                }
                else
                {
                    partyType = partyTypeManager.PartyTypeRepository.Get(parentTypeId);
                    parties   = partyManager.PartyRepository.Get().Where(p => p.PartyType.Id.Equals(parentTypeId)).ToList();
                }

                if (parties != null)
                {
                    foreach (var p in parties)
                    {
                        mask = mappings.FirstOrDefault().TransformationRule.Mask;

                        foreach (var mapping in mappings)
                        {
                            long attributeId = mapping.Source.ElementId;


                            PartyCustomAttributeValue attrValue =
                                partyManager.PartyCustomAttributeValueRepository.Get()
                                .Where(v => v.CustomAttribute.Id.Equals(attributeId) && v.Party.Id.Equals(p.Id))
                                .FirstOrDefault();



                            List <string> regExResultList = transform(attrValue.Value, mapping.TransformationRule);
                            string        placeHolderName = attrValue.CustomAttribute.Name;


                            mask = setOrReplace(mask, regExResultList, placeHolderName);
                        }

                        if (mask.ToLower().Contains(value.ToLower()))
                        {
                            tmp.Add(mask);
                        }
                    }
                }
            }

            return(tmp);
        }
Beispiel #27
0
        public static LinkElementRootModel LoadfromSystem(LinkElementPostion rootModelType, MappingManager mappingManager)
        {
            //get all parties - complex
            PartyTypeManager partyTypeManager = new PartyTypeManager();

            try
            {
                LinkElementRootModel model = new LinkElementRootModel(LinkElementType.System, 0, "System", rootModelType);

                LinkElement SystemRoot = mappingManager.GetLinkElement(0, LinkElementType.System);

                long id        = 0;
                long elementId = 0;
                if (SystemRoot != null)
                {
                    id        = SystemRoot.Id;
                    elementId = SystemRoot.ElementId;
                }


                LinkElementModel LEParent = new LinkElementModel(
                    id,
                    elementId,
                    LinkElementType.System,
                    "System", "",
                    rootModelType,
                    LinkElementComplexity.Complex,
                    "");



                IEnumerable <PartyType> partyTypes = partyTypeManager.PartyTypeRepository.Get();

                foreach (var pt in partyTypes)
                {
                    LinkElementModel ptModel = createLinkElementModelType(pt, model, LEParent, mappingManager);
                    model.LinkElements.Add(ptModel);
                    //get all partyCustomTypeAttr -> simple
                    model.LinkElements.AddRange(createLinkElementModelPartyCustomType(pt, model, ptModel, mappingManager));
                }

                //get all keys -> simple
                foreach (Key value in Key.GetValues(typeof(Key)))
                {
                    long linkElementId = GetId((int)value, LinkElementType.Key, mappingManager);
                    //string mask = GetMask((int)value, LinkElementType.Key);

                    LinkElementModel LEModel = new LinkElementModel(
                        linkElementId,
                        (int)value,
                        LinkElementType.Key, value.ToString(), "", model.Position, LinkElementComplexity.Simple, "");

                    LEModel.Parent = LEParent;

                    model.LinkElements.Add(LEModel);
                }

                //create container
                model = CreateLinkElementContainerModels(model);

                return(model);
            }
            finally
            {
                partyTypeManager.Dispose();
            }
        }
Beispiel #28
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);//
                    }
                }
            }
        }
Beispiel #29
0
        public static LinkElementRootModel LoadfromSystem(LinkElementPostion rootModelType, MappingManager mappingManager)
        {
            //get all parties - complex
            using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                using (PartyRelationshipTypeManager partyRelationshipTypeManager = new PartyRelationshipTypeManager())
                    using (EntityManager entityManager = new EntityManager())
                    {
                        LinkElementRootModel model = new LinkElementRootModel(LinkElementType.System, 0, "System", rootModelType);

                        LinkElement SystemRoot = mappingManager.GetLinkElement(0, LinkElementType.System);

                        long id        = 0;
                        long elementId = 0;
                        if (SystemRoot != null)
                        {
                            id        = SystemRoot.Id;
                            elementId = SystemRoot.ElementId;
                        }

                        LinkElementModel LEParent = new LinkElementModel(
                            id,
                            elementId,
                            LinkElementType.System,
                            "System", "",
                            rootModelType,
                            LinkElementComplexity.Complex,
                            "");

                        #region get party types

                        IEnumerable <PartyType> partyTypes = partyTypeManager.PartyTypeRepository.Get();

                        foreach (var pt in partyTypes)
                        {
                            LinkElementModel ptModel = createLinkElementModelType(pt, model, LEParent, mappingManager);
                            model.LinkElements.Add(ptModel);
                            //get all partyCustomTypeAttr -> simple
                            model.LinkElements.AddRange(createLinkElementModelPartyCustomType(pt, model, ptModel, mappingManager));
                        }

                        #endregion get party types

                        #region keys

                        //get all keys -> simple
                        foreach (Key value in Key.GetValues(typeof(Key)))
                        {
                            long linkElementId = GetId((int)value, LinkElementType.Key, mappingManager);
                            //string mask = GetMask((int)value, LinkElementType.Key);

                            LinkElementModel LEModel = new LinkElementModel(
                                linkElementId,
                                (int)value,
                                LinkElementType.Key, value.ToString(), "", model.Position, LinkElementComplexity.Simple, "");

                            LEModel.Parent = LEParent;

                            model.LinkElements.Add(LEModel);
                        }

                        #endregion keys

                        #region get all relationships

                        IEnumerable <PartyRelationshipType> relationshipTypes = partyRelationshipTypeManager.PartyRelationshipTypeRepository.Get();

                        foreach (PartyRelationshipType partyRelationshipType in relationshipTypes)
                        {
                            long value         = partyRelationshipType.Id;
                            long linkElementId = GetId(partyRelationshipType.Id, LinkElementType.Key, mappingManager);

                            LinkElementModel LEModel = new LinkElementModel(
                                linkElementId,
                                partyRelationshipType.Id,
                                LinkElementType.PartyRelationshipType,
                                partyRelationshipType.DisplayName,
                                "",
                                model.Position,
                                LinkElementComplexity.Simple,
                                "");

                            LEModel.Parent = LEParent;

                            model.LinkElements.Add(LEModel);
                        }

                        #endregion get all relationships

                        #region entities

                        foreach (Entity entity in entityManager.Entities)
                        {
                            long value         = entity.Id;
                            long linkElementId = GetId(entity.Id, LinkElementType.Entity, mappingManager);

                            LinkElementModel LEModel = new LinkElementModel(
                                linkElementId,
                                entity.Id,
                                LinkElementType.Entity,
                                entity.Name,
                                "",
                                model.Position,
                                LinkElementComplexity.Simple,
                                "");

                            LEModel.Parent = LEParent;

                            model.LinkElements.Add(LEModel);
                        }

                        //test

                        #endregion entities

                        //create container
                        model = CreateLinkElementContainerModels(model);

                        return(model);
                    }
        }
Beispiel #30
0
        //toDo put this function to DIM
        public void SetRelationships(long datasetid, long metadataStructureId, XmlDocument metadata)
        {
            using (PartyManager partyManager = new PartyManager())
                using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                    using (PartyRelationshipTypeManager partyRelationshipTypeManager = new PartyRelationshipTypeManager())
                    {
                        try
                        {
                            using (var uow = this.GetUnitOfWork())
                            {
                                //check if mappings exist between system/relationships and the metadatastructure/attr
                                // get all party mapped nodes
                                IEnumerable <XElement> complexElements = XmlUtility.GetXElementsByAttribute("partyid", XmlUtility.ToXDocument(metadata));



                                // get releaionship type id for owner
                                var releationships = uow.GetReadOnlyRepository <PartyRelationshipType>().Get().Where(
                                    p => p.AssociatedPairs.Any(
                                        ap => ap.SourcePartyType.Title.ToLower().Equals("dataset") || ap.TargetPartyType.Title.ToLower().Equals("dataset")
                                        ));

                                foreach (XElement item in complexElements)
                                {
                                    if (item.HasAttributes)
                                    {
                                        long   sourceId = Convert.ToInt64(item.Attribute("id").Value);
                                        string type     = item.Attribute("type").Value;
                                        long   partyid  = Convert.ToInt64(item.Attribute("partyid").Value);

                                        LinkElementType sourceType = LinkElementType.MetadataNestedAttributeUsage;
                                        if (type.Equals("MetadataPackageUsage"))
                                        {
                                            sourceType = LinkElementType.MetadataPackageUsage;
                                        }

                                        foreach (var releationship in releationships)
                                        {
                                            // when mapping in both directions are exist
                                            if (MappingUtils.ExistMappings(sourceId, sourceType, releationship.Id, LinkElementType.PartyRelationshipType) &&
                                                MappingUtils.ExistMappings(releationship.Id, LinkElementType.PartyRelationshipType, sourceId, sourceType))
                                            {
                                                // create releationship

                                                // create a Party for the dataset
                                                var customAttributes = new Dictionary <String, String>();
                                                customAttributes.Add("Name", datasetid.ToString());
                                                customAttributes.Add("Id", datasetid.ToString());

                                                var datasetParty = partyManager.Create(partyTypeManager.PartyTypeRepository.Get(cc => cc.Title == "Dataset").First(), "[description]", null, null, customAttributes);
                                                var person       = partyManager.GetParty(partyid);


                                                var partyTpePair = releationship.PartyRelationships.FirstOrDefault().PartyTypePair;

                                                if (partyTpePair != null && person != null && datasetParty != null)
                                                {
                                                    partyManager.AddPartyRelationship(
                                                        datasetParty.Id,
                                                        person.Id,
                                                        "Owner Releationship",
                                                        "",
                                                        partyTpePair.Id

                                                        );
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
        }