Esempio n. 1
0
        public bool RemoveStatusType(PartyStatusType entity)
        {
            Contract.Requires(entity != null && entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyStatusType> repo = uow.GetRepository <PartyStatusType>();
                var latest = repo.Reload(entity);
                if (latest.Statuses.Count() > 0)
                {
                    BexisException.Throw(latest, "There are some relevent 'PartStatus' to this entity.", BexisException.ExceptionType.Delete);
                }

                //Atleast one 'PartyStatusType' is required for each 'PartyType' and 'PartyType' for this entity just has this 'PartyStatusType'.
                if (latest.PartyType.StatusTypes.Count() > 1)
                {
                    BexisException.Throw(latest, "Atleast one 'PartyStatusType' is required for each 'PartyType' and 'PartyType' for this entity just has this 'PartyStatusType'.", BexisException.ExceptionType.Delete);
                }
                //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. 2
0
        public PartyStatusType AddStatusType(PartyType partyType, string name, string description, int displayOrder)
        {
            // reorder the other status types that confclict with the displayOrder passed here
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(partyType != null && partyType.Id > 0);

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

            var entity = new PartyStatusType()
            {
                Description  = description,
                DisplayOrder = displayOrder,
                Name         = name,
                PartyType    = partyType
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <PartyStatusType> repo = uow.GetRepository <PartyStatusType>();
                var ff = repo.Get(item => item.Name == name && item.PartyType == partyType);
                //Name and partyType are unique in PartyStatusTypes
                if (repo.Get(item => item.Name == name && item.PartyType == partyType).Count() > 0)
                {
                    BexisException.Throw(entity, "This name with this PartyType is already exist.", BexisException.ExceptionType.Add);
                }

                repo.Put(entity);
                uow.Commit();
            }
            return(entity);
        }
Esempio n. 3
0
        private void CreatePartys()
        {
            #region CREATE PARTYS
            PartyManager     partyManager     = new PartyManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();

            PartyType partyType = partyTypeManager.PartyTypeRepository.Get().Where(p => p.Title.Equals("Person")).FirstOrDefault();

            if (partyType != null)
            {
                PartyStatusType partyStatusType = partyTypeManager.AddStatusType(partyType, "just created",
                                                                                 "this is for test data", 0);

                var p = partyManager.Create(partyType, "David Blaa", "desc", null, null, partyStatusType);
                // add value
                var pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("FirstName")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "David");

                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("LastName")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "Schöne");

                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("Email")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "*****@*****.**");

                /***********************************/
                p = partyManager.Create(partyType, "Sven Thiel", "desc", null, null, partyStatusType);
                // add value
                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("FirstName")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "Sven");

                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("LastName")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "Thiel");

                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("Email")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "*****@*****.**");

                /***********************************/
                p = partyManager.Create(partyType, "Martin Hohmuth", "desc", null, null, partyStatusType);
                // add value
                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("FirstName")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "Martin");

                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("LastName")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "Hohmuth");

                pAttr = partyTypeManager.PartyCustomAttributeRepository.Get().Where(a => a.Name.Equals("Email")).FirstOrDefault();
                partyManager.AddPartyCustomAttributeValue(ref p, pAttr, "*****@*****.**");
            }



            #endregion
        }
Esempio n. 4
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. 5
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);
        }