Inheritance: BaseEntity
Esempio n. 1
0
 public ActionResult Delete(Party party)
 {
     PartyManager partyManager = new PartyManager();
     //  party = partyManager.Repo.Reload(party);
     partyManager.Delete(party);
     return RedirectToAction("Index");
 }
Esempio n. 2
0
        public PartyX Update(PartyX party)
        {
            Contract.Requires(party != null, "Provided entity can not be null");
            Contract.Requires(party.Id >= 0, "Provided entity must have a permanent ID");
            Contract.Ensures(Contract.Result <PartyX>() != null && Contract.Result <PartyX>().Id >= 0, "No entity is persisted!");

            if (party.StartDate == null)
            {
                party.StartDate = DateTime.MinValue;
            }
            if (party.EndDate == null || party.EndDate == DateTime.MinValue)
            {
                party.EndDate = DateTime.MaxValue;
            }
            if (party.StartDate > party.EndDate)
            {
                BexisException.Throw(null, "End date should be greater than start date.");
            }
            if ((ValidateRelationships(party.Id)).Any())
            {
                party.IsTemp = true;
            }
            else
            {
                party.IsTemp = false;
            }

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyX> repo = uow.GetRepository <PartyX>();
                repo.Merge(party);
                var merged = repo.Get(party.Id);
                repo.Put(merged);
                uow.Commit();
            }
            return(party);

            //using (IUnitOfWork uow = this.GetUnitOfWork())
            //{
            //    IRepository<PartyX> repo = uow.GetRepository<PartyX>();
            //    var newParty = repo.Reload(party);
            //    newParty.Alias = party.Alias;
            //    newParty.CurrentStatus = party.CurrentStatus;
            //    newParty.Description = party.Description;
            //    newParty.EndDate = party.EndDate;
            //    newParty.Extra = party.Extra;
            //    newParty.IsTemp = party.IsTemp;
            //    newParty.Name = party.Name;
            //    newParty.PartyType = party.PartyType;
            //    newParty.StartDate = party.StartDate;
            //    //TODO:What to do ????
            //    repo.Put(newParty); // Merge is required here!!!!
            //    uow.Commit();
            //    party = repo.Reload(party);
            //}
            //return (party);
        }
Esempio n. 3
0
 public void AddPartyUser(PartyX party, long userId)
 {
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         var partyUser = new PartyUser();
         partyUser.UserId  = userId;
         partyUser.PartyId = party.Id;
         partyUser.Party   = party;
         IRepository <PartyUser> repo = uow.GetRepository <PartyUser>();
         repo.Put(partyUser);
         uow.Commit();
     }
 }
Esempio n. 4
0
 public void RemovePartyUser(PartyX party, long userId)
 {
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         IRepository <PartyUser> repo = uow.GetRepository <PartyUser>();
         var partyUser = repo.Get(cc => cc.PartyId == party.Id && cc.UserId == userId);
         if (partyUser != null)
         {
             repo.Delete(partyUser);
         }
         uow.Commit();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// add a single custom attribute value to a party object
        ///
        /// It's not checking uniqeness when it is not for a single custom attribute because it couldn't predict other values--> it should have all values to make a hash
        /// </summary>
        /// <param name="party"></param>
        /// <param name="partyCustomAttribute"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public PartyCustomAttributeValue AddPartyCustomAttributeValue(ref PartyX party, PartyCustomAttribute partyCustomAttribute, string value)
        {
            // create a dictionary to pass along
            var dic = new Dictionary <PartyCustomAttribute, string>
            {
                { partyCustomAttribute, value }
            };

            // pass along
            var result = AddPartyCustomAttributeValues(ref party, dic);

            // find the corresponding attribute in the result
            return(result.Where((item) => (item.CustomAttribute == partyCustomAttribute) && (item.Value == value)).FirstOrDefault());
        }
Esempio n. 6
0
        //Currently there is no need to use name due to the conversation in a project meeting on December</param>
        /// <summary>
        /// Create a party
        /// </summary>
        /// <param name="partyType"></param>
        /// <param name="alias"></param>
        /// <param name="description"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="initialStatusType"></param>
        /// <param name="isTemp"></param>
        /// <returns></returns>
        public PartyX Create(PartyType partyType, string alias, string description, DateTime?startDate, DateTime?endDate, PartyStatusType initialStatusType, bool isTemp = true)
        {
            //Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(partyType != null);
            Contract.Requires(initialStatusType != null);
            Contract.Requires(partyType.StatusTypes.Any(cc => cc.Id == initialStatusType.Id));
            Contract.Ensures(Contract.Result <PartyX>() != null && Contract.Result <PartyX>().Id >= 0);
            if (startDate == null)
            {
                startDate = DateTime.MinValue;
            }
            if (endDate == null || endDate == DateTime.MinValue)
            {
                endDate = DateTime.MaxValue;
            }
            if (startDate > endDate)
            {
                BexisException.Throw(null, "End date should be greater than start date.");
            }

            //Create a create status
            PartyStatus initialStatus = new PartyStatus();

            initialStatus.Timestamp   = DateTime.UtcNow;
            initialStatus.Description = "Created";
            initialStatus.StatusType  = initialStatusType;

            PartyX entity = new PartyX()
            {
                PartyType     = partyType,
                Alias         = alias,
                Description   = description,
                StartDate     = startDate.Value,
                EndDate       = endDate.Value,
                CurrentStatus = initialStatus,
                IsTemp        = isTemp
            };

            initialStatus.Party = entity;
            entity.History      = new List <PartyStatus>();
            entity.History.Add(initialStatus);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyX> repo = uow.GetRepository <PartyX>();
                repo.Put(entity); // must store the status objects too
                uow.Commit();
            }
            return(entity);
        }
Esempio n. 7
0
 private PartyX UpdatePartyName(PartyX party)
 {
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         IRepository <PartyX> repo = uow.GetRepository <PartyX>();
         //party = repo.Reload(party);
         var mainValues = party.CustomAttributeValues.Where(item => item.CustomAttribute.IsMain).Select(item => item.Value).ToArray();
         if (mainValues.Length > 0)
         {
             party.Name = string.Join(" ", mainValues); // what should happen when no custom attribute is there!?
             repo.Merge(party);
             var merged = repo.Get(party.Id);
             repo.Put(merged);
             uow.Commit();
         }
         return(party);
     }
 }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="party"></param>
        /// <param name="partyCustomAttributeValues"></param>
        /// <returns></returns>
        public IEnumerable <PartyCustomAttributeValue> AddPartyCustomAttributeValues(ref PartyX party, Dictionary <PartyCustomAttribute, string> partyCustomAttributeValues)
        {
            Contract.Requires(partyCustomAttributeValues != null);
            Contract.Requires(party != null);
            Contract.Requires(party.Id >= 0, "Provided party entity must have a permanent ID");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyX> repo = uow.GetRepository <PartyX>();
                IRepository <PartyCustomAttributeValue> repoCAV = uow.GetRepository <PartyCustomAttributeValue>();
                IRepository <PartyCustomAttribute>      repoCA  = uow.GetRepository <PartyCustomAttribute>();
                party = repo.Reload(party);
                if (!CheckUniqueness(repo, party.PartyType, partyCustomAttributeValues, party))
                {
                    BexisException.Throw(party, String.Format("Due the party uniqueness policy for this party type this value couldn't save"), BexisException.ExceptionType.Add, true);
                }
                foreach (var partyCustomAttributeValue in partyCustomAttributeValues)
                {
                    //check if there is the same custom attribute for this party update it
                    var entity = party.CustomAttributeValues.FirstOrDefault(item => item.CustomAttribute.Id == partyCustomAttributeValue.Key.Id);
                    if (entity != null)
                    {
                        entity.Value = partyCustomAttributeValue.Value;
                    }
                    else
                    {
                        entity = new PartyCustomAttributeValue()
                        {
                            CustomAttribute = partyCustomAttributeValue.Key,
                            Party           = party,
                            Value           = partyCustomAttributeValue.Value
                        };
                        party.CustomAttributeValues.Add(entity);
                    }
                    repoCAV.Put(entity);
                }
                uow.Commit();
            }
            party = UpdatePartyName(party);
            return(party.CustomAttributeValues);
        }
Esempio n. 9
0
        public PartyCustomAttributeValue AddPartyCustomAttriuteValue(PartyX party, PartyCustomAttribute partyCustomAttribute, string value)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(value));
            Contract.Requires(partyCustomAttribute != null);
            Contract.Requires(partyCustomAttribute.Id >= 0, "Provided Custom Attribute entity must have a permanent identifier.");
            Contract.Requires(party != null);
            Contract.Requires(party.Id >= 0, "Provided party entity must have a permanent ID");

            Contract.Ensures(Contract.Result<PartyCustomAttributeValue>() != null && Contract.Result<PartyCustomAttributeValue>().Id >= 0);

            var entity = new PartyCustomAttributeValue()
            {
                CustomAttribute = partyCustomAttribute,
                Value = value
            };
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                IRepository<PartyCustomAttributeValue> repoCAV = uow.GetRepository<PartyCustomAttributeValue>();
                var partyEntity = repo.Reload(party);
                //if there is no attribute value when it created
                if (partyEntity.CustomAttributeValues == null)
                    partyEntity.CustomAttributeValues = new List<PartyCustomAttributeValue>();
                //check if there is the same custom attribute for this party update it
                var similarPartyCustomAttr = partyEntity.CustomAttributeValues.FirstOrDefault(item => item.CustomAttribute.Id == partyCustomAttribute.Id);
                if (similarPartyCustomAttr != null)
                {
                    similarPartyCustomAttr.Value = value;
                    entity = similarPartyCustomAttr;
                }
                else
                {
                    partyEntity.CustomAttributeValues.Add(entity);
                    repoCAV.Put(entity);
                }
                uow.Commit();
            }
            return (entity);
        }
Esempio n. 10
0
        public PartyStatus AddPartyStatus(PartyX party, PartyStatusType partyStatusType, string description)
        {
            Contract.Requires(party != null);
            Contract.Requires(partyStatusType != null);
            Contract.Ensures(Contract.Result <PartyStatus>() != null && Contract.Result <PartyStatus>().Id >= 0);
            var entity = new PartyStatus()
            {
                Description = description,
                Party       = party,
                StatusType  = partyStatusType,
                Timestamp   = DateTime.Now
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyStatus> repoStatus = uow.GetRepository <PartyStatus>();

                repoStatus.Put(entity);
                // The current status must get updated, too. dependes on the current status's update logic.
                uow.Commit();
            }
            return(entity);
        }
Esempio n. 11
0
        public bool Delete(PartyX entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyRelationship>         repoRel            = uow.GetRepository <PartyRelationship>();
                IRepository <PartyX>                    repo               = uow.GetRepository <PartyX>();
                IRepository <PartyUser>                 repoPartyUser      = uow.GetRepository <PartyUser>();
                IRepository <PartyStatus>               repoCM             = uow.GetRepository <PartyStatus>();
                IRepository <PartyCustomAttributeValue> repoCustomeAttrVal = uow.GetRepository <PartyCustomAttributeValue>();

                var latest = repo.Reload(entity);
                // remove all associations between the entity and its history items
                //remove all relations
                var relations = repoRel.Get(item => item.FirstParty.Id == entity.Id || item.SecondParty.Id == entity.Id);
                repoRel.Delete(relations);
                //Remove from user if there is
                repoPartyUser.Delete(repoPartyUser.Get(cc => cc.PartyId == entity.Id));
                //Remove all the histories
                repoCM.Delete(latest.History);
                if (latest.History.Count() > 0)
                {
                    latest.History.ToList().ForEach(a => a.Party = null);
                    latest.History.Clear();
                }
                //remove all 'CustomAttributeValues'
                repoCustomeAttrVal.Delete(latest.CustomAttributeValues);
                latest.CustomAttributeValues.Clear();
                //delete the entity
                repo.Delete(latest);
                // commit changes
                uow.Commit();
            }
            // if any problem was detected during the commit, an exception will be thrown!
            return(true);
        }
Esempio n. 12
0
        /// <summary>
        /// make a hash from isUniqe custom attributes and check it with all of the other parties hash
        /// </summary>
        /// <param name="partyType"></param>
        /// <param name="partyCustomAttrVals"></param>
        /// <returns></returns>
        public bool CheckUniqueness(IReadOnlyRepository <PartyX> repo, List <PartyCustomAttributeValue> partyCustomAttrVals, PartyX currentParty = null)
        {
            Contract.Requires(partyCustomAttrVals.Any(), "Provided list must have one entity at least.");
            var    partyTypeId = partyCustomAttrVals.First().CustomAttribute.PartyType.Id;
            string hash        = GetHash(partyCustomAttrVals);

            if (!string.IsNullOrEmpty(hash))
            {
                var parties = repo.Get(item => item.PartyType.Id == partyTypeId);
                if (currentParty != null && currentParty.Id != 0)
                {
                    parties = parties.Where(item => item.Id != currentParty.Id).ToList();
                }
                foreach (var party in parties)
                {
                    if (hash == GetHash(party.CustomAttributeValues.ToList()))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 13
0
        public PartyRelationship AddPartyRelationship(PartyX firstParty, PartyX secondParty, PartyRelationshipType partyRelationshipType,
            string title, string description, DateTime? startDate = null, DateTime? endDate = null, string scope = "")
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(title));
            Contract.Requires(firstParty != null);
            Contract.Requires(firstParty.Id >= 0, "Provided first entity must have a permanent ID");
            Contract.Requires(secondParty != null);
            Contract.Requires(secondParty.Id >= 0, "Provided first entity must have a permanent ID");
            Contract.Requires(partyRelationshipType != null && partyRelationshipType.Id > 0);
            Contract.Ensures(Contract.Result<PartyRelationship>() != null && Contract.Result<PartyRelationship>().Id >= 0);
            if (startDate == null)
                startDate = DateTime.MinValue;
            if (endDate == null)
                endDate = DateTime.MaxValue;
            var entity = new PartyRelationship()
            {
                Description = description,
                EndDate = endDate.Value,
                FirstParty = firstParty,
                PartyRelationshipType = partyRelationshipType,
                Scope = scope,
                SecondParty = secondParty,
                StartDate = startDate.Value,
                Title = title
            };
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyRelationship> repoPR = uow.GetRepository<PartyRelationship>();
                IRepository<PartyRelationshipType> repoRelType = uow.GetRepository<PartyRelationshipType>();
                partyRelationshipType = repoRelType.Reload(partyRelationshipType);
                //Check if there is another relationship
                var cnt = repoPR.Query(item => (item.PartyRelationshipType != null && item.PartyRelationshipType.Id == partyRelationshipType.Id)
                                        && (item.FirstParty != null && item.FirstParty.Id == firstParty.Id)
                                         && (item.SecondParty != null && item.SecondParty.Id == secondParty.Id)).Count();
                //if ( > 0)
                //    BexisException.Throw(entity, "This relationship is already exist in database.", BexisException.ExceptionType.Add);
                //Check maximun cardinality
                if (partyRelationshipType.MaxCardinality <= cnt)
                    BexisException.Throw(entity, string.Format("Maximum relations for this type of relation is {0}.", partyRelationshipType.MaxCardinality), BexisException.ExceptionType.Add);

                //Check if there is a relevant party type pair
                var alowedSource = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.AlowedSource == firstParty.PartyType || item.AlowedSource == secondParty.PartyType);
                var alowedTarget = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.AlowedTarget == firstParty.PartyType || item.AlowedTarget == secondParty.PartyType);
                if (alowedSource == null || alowedTarget == null)
                    BexisException.Throw(entity, string.Format("There is not relevant 'PartyTypePair' for these types of parties.", partyRelationshipType.MaxCardinality), BexisException.ExceptionType.Add);

                partyRelationshipType.PartyRelationships.Add(entity);
                repoPR.Put(entity);
                uow.Commit();
            }
            return (entity);
        }
Esempio n. 14
0
        public PartyStatus AddPartyStatus(PartyX party, PartyStatusType partyStatusType, string description)
        {
            Contract.Requires(party != null);
            Contract.Requires(partyStatusType != null);
            Contract.Ensures(Contract.Result<PartyStatus>() != null && Contract.Result<PartyStatus>().Id >= 0);
            var entity = new PartyStatus()
            {
                Description = description,
                Party = party,
                StatusType = partyStatusType,
                Timestamp = DateTime.Now
            };
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyStatus> repoStatus = uow.GetRepository<PartyStatus>();

                repoStatus.Put(entity);
                // The current status must get updated, too. dependes on the current status's update logic.
                uow.Commit();
            }
            return (entity);
        }
Esempio n. 15
0
 public IEnumerable <PartyCustomAttributeValue> AddPartyCustomAttributeValues(PartyX party, Dictionary <long, string> partyCustomAttributeValues)
 {
     return(AddPartyCustomAttributeValues(ref party, ConvertDictionaryToPartyCustomeAttrValuesDictionary(partyCustomAttributeValues)));
 }
Esempio n. 16
0
 public PartyCustomAttributeValue UpdatePartyCustomAttriuteValue(PartyCustomAttribute partyCustomAttribute,PartyX party,string value)
 {
     Contract.Requires(partyCustomAttribute != null && party != null, "Provided entities can not be null");
     Contract.Requires(partyCustomAttribute.Id >= 0 && party.Id >= 0, "Provided entitities must have a permanent ID");
     Contract.Ensures(Contract.Result<PartyCustomAttributeValue>() != null && Contract.Result<PartyCustomAttributeValue>().Id >= 0, "No entity is persisted!");
     var entity = new PartyCustomAttributeValue();
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         IRepository<PartyCustomAttributeValue> repo = uow.GetRepository<PartyCustomAttributeValue>();
         entity = repo.Get(item => item.Party.Id == party.Id && item.CustomAttribute.Id == partyCustomAttribute.Id).FirstOrDefault();
         entity.Value = value;
         repo.Put(entity); // Merge is required here!!!!
         uow.Commit();
         entity = repo.Reload(entity);
     }
     return (entity);
 }
Esempio n. 17
0
        public PartyRelationship AddPartyRelationship(PartyX firstParty, PartyX secondParty, PartyRelationshipType partyRelationshipType,
                                                      string title, string description, PartyTypePair partyTypePair, DateTime?startDate = null, DateTime?endDate = null, string scope = "")
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(title));
            Contract.Requires(firstParty != null);
            Contract.Requires(firstParty.Id >= 0, "Provided first entity must have a permanent ID");
            Contract.Requires(secondParty != null);
            Contract.Requires(secondParty.Id >= 0, "Provided first entity must have a permanent ID");
            Contract.Requires(partyRelationshipType != null && partyRelationshipType.Id > 0);
            Contract.Ensures(Contract.Result <PartyRelationship>() != null && Contract.Result <PartyRelationship>().Id >= 0);
            if (startDate == null)
            {
                startDate = DateTime.MinValue;
            }
            if (endDate == null)
            {
                endDate = DateTime.MaxValue;
            }
            if (startDate > endDate)
            {
                BexisException.Throw(firstParty, "End date should be greater than start date.");
            }
            var entity = new PartyRelationship()
            {
                Description           = description,
                EndDate               = endDate.Value,
                FirstParty            = firstParty,
                PartyRelationshipType = partyRelationshipType,
                Scope       = scope,
                SecondParty = secondParty,
                StartDate   = startDate.Value,
                Title       = title
            };

            if (partyTypePair != null)
            {
                entity.PartyTypePair = partyTypePair;
            }
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyX>                repoParty   = uow.GetRepository <PartyX>();
                IRepository <PartyRelationship>     repoPR      = uow.GetRepository <PartyRelationship>();
                IRepository <PartyRelationshipType> repoRelType = uow.GetRepository <PartyRelationshipType>();
                partyRelationshipType = repoRelType.Reload(partyRelationshipType);
                var cnt = repoPR.Query(item => (item.PartyRelationshipType != null && item.PartyRelationshipType.Id == partyRelationshipType.Id) &&
                                       (item.FirstParty != null && item.FirstParty.Id == firstParty.Id) &&
                                       (item.SecondParty != null && item.SecondParty.Id == secondParty.Id)).Where(item => item.EndDate > startDate).Count();
                //Check maximun cardinality
                if (partyRelationshipType.MaxCardinality != -1 && partyRelationshipType.MaxCardinality <= cnt)
                {
                    BexisException.Throw(entity, string.Format("Maximum relations for this type of relation is {0}.", partyRelationshipType.MaxCardinality), BexisException.ExceptionType.Add);
                }

                //Check if there is a relevant party type pair
                var alowedSource = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.AllowedSource.Id == firstParty.PartyType.Id || item.AllowedSource.Id == secondParty.PartyType.Id);
                var alowedTarget = partyRelationshipType.AssociatedPairs.FirstOrDefault(item => item.AllowedTarget.Id == firstParty.PartyType.Id || item.AllowedTarget.Id == secondParty.PartyType.Id);
                if (alowedSource == null || alowedTarget == null)
                {
                    BexisException.Throw(entity, "There is not relevant 'PartyTypePair' for these types of parties.", BexisException.ExceptionType.Add);
                }
                partyRelationshipType.PartyRelationships.Add(entity);
                repoPR.Put(entity);
                uow.Commit();
                //update the source party to check if relationship rules are satisfied and changed the istemp field
                Update(entity.FirstParty);
            }
            return(entity);
        }
Esempio n. 18
0
 public bool Delete(PartyX entity)
 {
     Contract.Requires(entity != null);
     Contract.Requires(entity.Id >= 0);
     using (IUnitOfWork uow = this.GetUnitOfWork())
     {
         IRepository<PartyX> repo = uow.GetRepository<PartyX>();
         IRepository<PartyStatus> repoCM = uow.GetRepository<PartyStatus>();
         IRepository<PartyRelationship> repoRel = uow.GetRepository<PartyRelationship>();
         IRepository<PartyCustomAttributeValue> repoCustomeAttrVal= uow.GetRepository<PartyCustomAttributeValue>();
         var latest = repo.Reload(entity);
         // remove all associations between the entity and its history items
         repoCM.Delete(latest.History);
         if (latest.History.Count()>0)
         {
             latest.History.ToList().ForEach(a => a.Party = null);
             latest.History.Clear();
         }
         //remove all 'CustomAttributeValues'
         repoCustomeAttrVal.Delete(latest.CustomAttributeValues);
         latest.CustomAttributeValues.Clear();
         //remove all relations
         var relations = repoRel.Get(item => item.FirstParty.Id == entity.Id || item.SecondParty.Id == entity.Id);
         foreach (var relation in relations)
         {
             repoRel.Delete(relation);
         }
         //delete the entity
         repo.Delete(latest);
         // commit changes
         uow.Commit();
     }
     // if any problem was detected during the commit, an exception will be thrown!
     return (true);
 }
Esempio n. 19
0
 public PartyModel()
 {
     Party = new Party();
     PartyTypeList = new List<PartyType>();
     Errors = new List<Error>();
 }
Esempio n. 20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="party"></param>
        /// <param name="partyCustomAttributeValues"></param>
        /// <returns></returns>
        public IEnumerable<PartyCustomAttributeValue> AddPartyCustomAttriuteValue(PartyX party, Dictionary<PartyCustomAttribute, string> partyCustomAttributeValues)
        {
            Contract.Requires(partyCustomAttributeValues != null);
            Contract.Requires(party != null);
            Contract.Requires(party.Id >= 0, "Provided party entity must have a permanent ID");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                IRepository<PartyCustomAttributeValue> repoCAV = uow.GetRepository<PartyCustomAttributeValue>();
                party = repo.Reload(party);

                foreach (var partyCustomAttributeValue in partyCustomAttributeValues)
                {
                    //check if there is the same custom attribute for this party update it
                    var similarPartyCustomAttr = party.CustomAttributeValues.FirstOrDefault(item => item.CustomAttribute.Id == partyCustomAttributeValue.Key.Id);
                    if (similarPartyCustomAttr != null)
                        similarPartyCustomAttr.Value = partyCustomAttributeValue.Value;
                    else
                    {
                        var entity = new PartyCustomAttributeValue()
                        {
                            CustomAttribute = partyCustomAttributeValue.Key,
                            Party=party,
                            Value = partyCustomAttributeValue.Value
                        };

                        repoCAV.Put(entity);
                    }
                }
                uow.Commit();
            }
            return party.CustomAttributeValues;
        }
Esempio n. 21
0
        /// <summary>
        /// make a hash from isUniqe custom attributes and check it with all of the other parties hash
        /// </summary>
        /// <param name="partyType"></param>
        /// <param name="partyCustomAttrVals"></param>
        /// <returns></returns>
        public bool CheckUniqueness(IReadOnlyRepository <PartyX> repo, PartyType partyType, Dictionary <PartyCustomAttribute, string> partyCustomAttrVals, PartyX currentParty = null)
        {
            string hash = GetHash(partyCustomAttrVals);

            if (!string.IsNullOrEmpty(hash))
            {
                var parties = repo.Get(item => item.PartyType.Id == partyType.Id);
                if (currentParty != null && currentParty.Id != 0)
                {
                    parties = parties.Where(item => item.Id != currentParty.Id).ToList();
                }
                foreach (var party in parties)
                {
                    if (hash == GetHash(party.CustomAttributeValues.ToList()))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 22
0
        public PartyX Create(PartyType partyType, string name, string alias, string description, DateTime? startDate, DateTime? endDate, PartyStatusType statusType)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(partyType != null);
            Contract.Requires(statusType != null);
            Contract.Requires(partyType.StatusTypes.Contains(statusType));
            Contract.Ensures(Contract.Result<PartyX>() != null && Contract.Result<PartyX>().Id >= 0);
            if (startDate == null)
                startDate = DateTime.MinValue;
            if (endDate == null || endDate==DateTime.MinValue)
                endDate = DateTime.MaxValue;
            //Create a create status
            PartyStatus initialStatus = new PartyStatus();
            initialStatus.Timestamp = DateTime.UtcNow;
            initialStatus.Description = "Created";
            initialStatus.StatusType = statusType;

            PartyX entity = new PartyX()
            {
                PartyType = partyType,
                Name = name,
                Alias = alias,
                Description = description,
                StartDate = startDate.Value,
                EndDate = endDate.Value,
                CurrentStatus = initialStatus
            };
            initialStatus.Party = entity;
            entity.History = new List<PartyStatus>();
            entity.History.Add(initialStatus);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                repo.Put(entity); // must store the status objects too
                uow.Commit();
            }
            return (entity);
        }
Esempio n. 23
0
        public PartyX Update(PartyX entity)
        {
            Contract.Requires(entity != null, "Provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "Provided entity must have a permanent ID");
            Contract.Ensures(Contract.Result<PartyX>() != null && Contract.Result<PartyX>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<PartyX> repo = uow.GetRepository<PartyX>();
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
                entity = repo.Reload(entity);
            }
            return (entity);
        }