Exemple #1
0
        public override void Execute()
        {
            base.Execute();

            if (_property == null)
            {
                return;
            }

            if (_getValueAtExecuteTime)
            {
                if (BasicActivator.SelectValueType(_property.Name, _property.PropertyType, _property.GetValue(_setOn), out object chosen))
                {
                    NewValue = chosen;
                }
                else
                {
                    Success = false;
                    return;
                }
            }

            ShareManager.SetValue(_property, NewValue, _setOn);
            ((DatabaseEntity)_setOn).SaveToDatabase();

            Success = true;
            Publish((DatabaseEntity)_setOn);
        }
Exemple #2
0
        public override void Execute()
        {
            base.Execute();

            if (_property == null)
            {
                return;
            }

            ShareManager.SetValue(_property, NewValue, null);
            Success = true;
        }
        public override void Execute()
        {
            base.Execute();

            if (_property == null)
            {
                return;
            }

            if (_getValueAtExecuteTime)
            {
                bool populatedNewValueWithRelationship = false;

                // If the property we are getting a value for is a foreign key ID field then we should show the user the compatible objects
                var rel = _property.GetCustomAttribute(typeof(RelationshipAttribute)) as RelationshipAttribute;
                if (rel != null && (_property.PropertyType == typeof(int) || _property.PropertyType == typeof(int?)))
                {
                    if (typeof(IMapsDirectlyToDatabaseTable).IsAssignableFrom(rel.Cref))
                    {
                        IMapsDirectlyToDatabaseTable[] available;

                        // is there a method that can be called to find compatible children for populating this property?
                        if (!string.IsNullOrWhiteSpace(rel.ValueGetter))
                        {
                            //get available from that method
                            var method = _setOn.GetType().GetMethod(rel.ValueGetter, new Type[0]);

                            if (method == null)
                            {
                                throw new Exception($"Could not find a method called '{rel.ValueGetter}' on Type '{_setOn.GetType()}'.  This was specified as a ValueGetter on Property {_property.Name}");
                            }

                            try
                            {
                                available = ((IEnumerable <IMapsDirectlyToDatabaseTable>)method.Invoke(_setOn, null)).ToArray();
                            }
                            catch (Exception ex)
                            {
                                throw new Exception($"Error running method '{rel.ValueGetter}' on Type '{_setOn.GetType()}'.  This was specified as a ValueGetter on Property {_property.Name}", ex);
                            }
                        }
                        else
                        {
                            available = BasicActivator.GetAll(rel.Cref).ToArray();
                        }

                        NewValue = BasicActivator.SelectOne(_property.Name, available)?.ID;
                        populatedNewValueWithRelationship = true;
                    }
                }

                if (!populatedNewValueWithRelationship)
                {
                    if (BasicActivator.SelectValueType(_property.Name, _property.PropertyType, _property.GetValue(_setOn), out object chosen))
                    {
                        NewValue = chosen;
                    }
                    else
                    {
                        Success = false;
                        return;
                    }
                }
            }

            ShareManager.SetValue(_property, NewValue, _setOn);
            ((DatabaseEntity)_setOn).SaveToDatabase();

            Success = true;
            Publish((DatabaseEntity)_setOn);
        }