Пример #1
0
        public ActionResult CreatePartyRelationships(int partyId, Dictionary <string, string> partyRelationshipsDic)
        {
            PartyManager partyManager = null;
            PartyRelationshipTypeManager partyRelationshipManager = null;

            try
            {
                partyManager = new PartyManager();
                var party = partyManager.PartyRepository.Get(partyId);
                var partyRelationships = ConvertDictionaryToPartyRelationships(partyRelationshipsDic, party, partyManager);
                partyRelationshipManager = new PartyRelationshipTypeManager();
                foreach (var partyRelationship in partyRelationships)
                {
                    // Party TargetParty = partyManager.PartyRepository.Get(partyRelationship.TargetParty.Id);
                    // PartyRelationshipType partyRelationshipType = partyRelationshipManager.PartyRelationshipTypeRepository.Get(partyRelationship.PartyRelationshipType.Id);
                    PartyTypePair partyTypePair = partyRelationshipManager.PartyTypePairRepository.Get(partyRelationship.PartyTypePair.Id);
                    //Min date value is sent from telerik date time element, if it was empty
                    if (partyRelationship.EndDate == DateTime.MinValue)
                    {
                        partyRelationship.EndDate = DateTime.MaxValue;
                    }
                    partyManager.AddPartyRelationship(partyRelationship.SourceParty, partyRelationship.TargetParty, partyRelationship.Title, partyRelationship.Description, partyTypePair, partyRelationship.StartDate, partyRelationship.EndDate, partyRelationship.Scope);
                }
                partyManager?.Dispose();
                return(RedirectToAction("CreateEdit", "party", new { id = partyId, relationTabAsDefault = true }));
            }
            finally
            {
                partyManager?.Dispose();
                partyRelationshipManager?.Dispose();
            }
        }
Пример #2
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"));
                            }
        }
Пример #3
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();
            }
        }
Пример #4
0
        public ActionResult CreatePartyRelationships(int partyId, Dictionary <string, string> partyRelationshipsDic)
        {
            PartyManager partyManager = null;

            try
            {
                partyManager = new PartyManager();
                Party party = partyManager.PartyRepository.Get(partyId);
                List <PartyRelationship> partyRelationships = ConvertDictionaryToPartyRelationships(partyRelationshipsDic);
                var partyRelationshipManager = new PartyRelationshipTypeManager();
                foreach (var partyRelationship in partyRelationships)
                {
                    Party secondParty = partyManager.PartyRepository.Get(partyRelationship.SecondParty.Id);
                    PartyRelationshipType partyRelationshipType = partyRelationshipManager.PartyRelationshipTypeRepository.Get(partyRelationship.PartyRelationshipType.Id);
                    PartyTypePair         partyTypePair         = partyRelationshipManager.PartyTypePairRepository.Get(partyRelationship.PartyTypePair.Id);
                    //Min date value is sent from telerik date time element, if it was empty
                    if (partyRelationship.EndDate == DateTime.MinValue)
                    {
                        partyRelationship.EndDate = DateTime.MaxValue;
                    }
                    partyManager.AddPartyRelationship(party, secondParty, partyRelationshipType, partyRelationship.Title, partyRelationship.Description, partyTypePair, partyRelationship.StartDate, partyRelationship.EndDate, partyRelationship.Scope);
                }
                partyManager?.Dispose();
                //partyManager = new PartyManager();
                ////if relationship rules are satisfied, it is not temp
                //  if (string.IsNullOrWhiteSpace(Helpers.Helper.ValidateRelationships(party.Id)))
                //    party.IsTemp = false;
                //else
                //    party.IsTemp = true;
                //partyManager.Update(party);
                return(RedirectToAction("CreateEdit", "party", new { id = partyId, relationTabAsDefault = true }));
            }
            finally
            {
                partyManager?.Dispose();
            }
        }
Пример #5
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;
                        }
                    }
        }