private static void SetStatusToActiveForCreate <T>(T entity) where T : Entity
        {
            var activeInfo = new ActivePropertyInfo <T>();

            if (activeInfo.ActiveAttribute == ActiveAttributeType.None)
            {
                return;
            }

            if (entity.Attributes.ContainsKey(activeInfo.AttributeName))
            {
                entity.Attributes.Remove(activeInfo.AttributeName);
            }

            switch (activeInfo.ActiveAttribute)
            {
            case ActiveAttributeType.IsDisabled:
                entity[activeInfo.AttributeName] = false;
                break;

            case ActiveAttributeType.StateCode:
                entity[activeInfo.AttributeName] = new OptionSetValue(activeInfo.ActiveState.GetValueOrDefault());
                break;

            case ActiveAttributeType.None:
                break;

            default:
                throw new EnumCaseUndefinedException <ActiveAttributeType>(activeInfo.ActiveAttribute);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether the specified service is active.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="entityId">The entity identifier.</param>
        /// <returns></returns>
        public static bool?IsActive(IOrganizationService service, Guid entityId)
        {
            var info   = new ActivePropertyInfo <T>();
            var entity = service.GetEntity <T>(entityId, new ColumnSet(info.AttributeName));

            return(IsActive(info, entity));
        }
Beispiel #3
0
        public static void IsNotActive <T>(IOrganizationService service, Guid id, string message = null, params object[] parameters) where T : Entity
        {
            var isActive = ActivePropertyInfo <T> .IsActive(service, id);

            if (isActive == null)
            {
                HandleInconclusive("AssertCrm.IsActive", "Unable to determine Status of Entity Type {0}", typeof(T).Name);
            }
            else if (isActive == true)
            {
                HandleFail("AssertCrm.IsActive", message, parameters);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Determines whether the specified information is active.
        /// </summary>
        /// <param name="info">The information.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">ActivePropertyInfo defines Attribute StateCode, but neither ActiveState or NotActiveState is popualted</exception>
        /// <exception cref="EnumCaseUndefinedException{ActiveAttributeType}"></exception>
        protected static bool?IsActive(ActivePropertyInfo <T> info, T entity)
        {
            bool?active;

            switch (info.ActiveAttribute)
            {
            case ActiveAttributeType.None:
                // Unable to determine
                active = null;
                break;

            case ActiveAttributeType.IsDisabled:
                active = !entity.GetAttributeValue <bool>(info.AttributeName);
                break;

            case ActiveAttributeType.StateCode:
                var state = entity.GetAttributeValue <OptionSetValue>(info.AttributeName).Value;
                if (info.ActiveState.HasValue)
                {
                    active = state == info.ActiveState;
                }
                else if (info.NotActiveState.HasValue)
                {
                    active = state != info.NotActiveState;
                }
                else
                {
                    throw new Exception("ActivePropertyInfo defines Attribute StateCode, but neither ActiveState or NotActiveState is popualted");
                }
                break;

            default:
                throw new EnumCaseUndefinedException <ActiveAttributeType>(info.ActiveAttribute);
            }

            return(active);
        }