public static bool IsAllowedEntityObject(CslaObjectInfo objectInfo)
        {
            if (objectInfo.IsEditableRoot() ||
                objectInfo.IsDynamicEditableRoot() ||
                objectInfo.IsEditableChild() ||
                objectInfo.IsEditableSwitchable() ||
                objectInfo.IsReadOnlyObject())
            {
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        // TODO Same "IsChildType" name but different results!!! When fixing, check also templates.
        public static bool IsChildType(this CslaObjectInfo info)
        {
            if (info.IsEditableSwitchable() ||
                info.IsEditableChild() ||
                info.IsEditableChildCollection() ||
                ((info.IsReadOnlyObject() ||
                  info.IsReadOnlyCollection()) &&
                 info.ParentType != string.Empty))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public static bool IsRootType(this CslaObjectInfo info)
        {
            if (info.IsEditableRoot() ||
                info.IsEditableRootCollection() ||
                info.IsDynamicEditableRoot() ||
                info.IsDynamicEditableRootCollection() ||
                info.IsEditableSwitchable() ||
                ((info.IsReadOnlyObject() ||
                  info.IsReadOnlyCollection()) &&
                 info.ParentType == string.Empty))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Should be called after the object has all it's properties (if applicable).
        /// It creates the default criteria classes depending on the object type.
        /// </summary>
        /// <param name="getSprocName">Name of the sproc.</param>
        internal void AddDefaultCriteriaAndParameters(string getSprocName)
        {
            if (_currentCslaObject.CriteriaObjects.Count != 0)
            {
                return;
            }

            if (_currentCslaObject.IsEditableRootCollection() ||
                _currentCslaObject.IsDynamicEditableRootCollection())
            {
                if (_currentUnit.Params.AutoCriteria)
                {
                    var crit = CreateEmptyNewAndFetchCriteria();
                    _currentCslaObject.CriteriaObjects.Add(crit);
                    crit.SetSprocNames();
                }
                //no need to go through the properties here.
                return;
            }

            if (_currentCslaObject.IsNameValueList() ||
                (_currentCslaObject.IsReadOnlyCollection() &&
                 _currentCslaObject.ParentType == string.Empty))
            {
                if (_currentUnit.Params.AutoCriteria)
                {
                    var crit = CreateEmptyFetchCriteria();
                    _currentCslaObject.CriteriaObjects.Add(crit);
                    crit.SetSprocNames(getSprocName);
                }
                //no need to go through the properties here.
                return;
            }

            // Condition excludes NameValueList
            if (_currentCslaObject.ObjectType.IsCollectionType())
            {
                return;
            }

            var           primaryKeyProperties = new List <ValueProperty>();
            ValueProperty timestampProperty    = null;
            var           useForCreate         = false;

            // retrieve all primary key and timestamp properties
            foreach (var prop in _currentCslaObject.ValueProperties)
            {
                if (prop.PrimaryKey != ValueProperty.UserDefinedKeyBehaviour.Default)
                {
                    primaryKeyProperties.Add(prop);
                    if (!(prop.DbBindColumn.IsIdentity || prop.PropertyType == TypeCodeEx.Guid))
                    {
                        useForCreate = true;
                    }
                }
                else if (prop.DbBindColumn.NativeType == "timestamp")
                {
                    timestampProperty = prop;
                }
            }

            if (primaryKeyProperties.Count > 0 || timestampProperty != null)
            {
                // Try to find default Criteria object
                Criteria defaultCriteria   = _currentCslaObject.CriteriaObjects.Find("Criteria");
                Criteria timestampCriteria = _currentCslaObject.CriteriaObjects.Find("CriteriaTS");

                // If criteria objects are not set
                if (_currentCslaObject.CriteriaObjects.Count == 0)
                {
                    // If default criteria doesn't exists, create a new criteria
                    if (defaultCriteria == null)
                    {
                        if (!(_currentCslaObject.IsReadOnlyObject() &&
                              _currentCslaObject.ParentType != string.Empty))
                        {
                            defaultCriteria      = new Criteria(_currentCslaObject);
                            defaultCriteria.Name = _currentCslaObject.IsReadOnlyObject()
                                ? "CriteriaGet"
                                : "Criteria";
                            defaultCriteria.GetOptions.Enable();
                            if (_currentCslaObject.IsEditableRoot() ||
                                _currentCslaObject.IsEditableSwitchable() ||
                                _currentCslaObject.IsEditableChild() ||
                                _currentCslaObject.IsDynamicEditableRoot())
                            {
                                defaultCriteria.DeleteOptions.Enable();
                                if (defaultCriteria.Properties.Count > 0 && useForCreate)
                                {
                                    defaultCriteria.CreateOptions.Factory    = true;
                                    defaultCriteria.CreateOptions.DataPortal = true;
                                    defaultCriteria.CreateOptions.RunLocal   = true;
                                }
                                else
                                {
                                    var createCriteria = _currentCslaObject.CriteriaObjects.Find("CriteriaNew");
                                    if (createCriteria == null)
                                    {
                                        createCriteria      = new Criteria(_currentCslaObject);
                                        createCriteria.Name = "CriteriaNew";
                                        createCriteria.CreateOptions.DataPortal = true;
                                        createCriteria.CreateOptions.Factory    = true;
                                        createCriteria.CreateOptions.RunLocal   = true;
                                        _currentCslaObject.CriteriaObjects.Add(createCriteria);
                                    }
                                }
                            }
                            if (_currentCslaObject.IsEditableChild())
                            {
                                return;
                            }

                            defaultCriteria.SetSprocNames();

                            if (_currentCslaObject.IsDynamicEditableRoot())
                            {
                                defaultCriteria.Name = "CriteriaDelete";
                                defaultCriteria.GetOptions.Factory       = false;
                                defaultCriteria.GetOptions.DataPortal    = false;
                                defaultCriteria.GetOptions.Procedure     = false;
                                defaultCriteria.GetOptions.ProcedureName = string.Empty;
                            }
                            else if (_currentCslaObject.IsNotEditableRoot() &&
                                     _currentCslaObject.IsNotEditableSwitchable() &&
                                     _currentCslaObject.IsNotReadOnlyObject())
                            {
                                defaultCriteria.Name = "CriteriaDelete";
                                defaultCriteria.GetOptions.Factory       = false;
                                defaultCriteria.GetOptions.DataPortal    = false;
                                defaultCriteria.GetOptions.Procedure     = false;
                                defaultCriteria.GetOptions.ProcedureName = string.Empty;
                                defaultCriteria.DeleteOptions.Factory    = false;
                                defaultCriteria.DeleteOptions.DataPortal = false;
                            }

                            _currentCslaObject.CriteriaObjects.Add(defaultCriteria);
                            AddPropertiesToCriteria(primaryKeyProperties, defaultCriteria);

                            if (_currentUnit.Params.AutoTimestampCriteria && timestampProperty != null &&
                                timestampCriteria == null)
                            {
                                AddTimestampProperty(defaultCriteria, timestampProperty);
                            }
                        }
                    }
                }
            }
            else if (getSprocName != string.Empty && _currentUnit.Params.AutoCriteria)
            {
                var crit = CreateEmptyFetchCriteria();
                _currentCslaObject.CriteriaObjects.Add(crit);
                crit.SetSprocNames(getSprocName);
            }
        }
Esempio n. 5
0
 public static bool IsNotEditableSwitchable(this CslaObjectInfo info)
 {
     return(!info.IsEditableSwitchable());
 }