Example #1
0
        public void Update(object entity, IEntityProperty[] activeProperties)
        {
            if (_entity == null)
            {
                _entity = entity;
                for (int i = 0; i < activeProperties.Length; i++)
                {
                    _properties.Add(activeProperties[i], null);
                }
            }
            else
            {
                for (int i = 0; i < activeProperties.Length; i++)
                {
                    object          nothing;
                    IEntityProperty property = activeProperties[i];

                    // Update the property value
                    property.SetValue(_entity, property.GetValue(entity));

                    if (!_properties.TryGetValue(property, out nothing))
                    {
                        _properties.Add(property, null);
                    }
                }
            }

            TimeUpdated = DateTime.Now;
        }
Example #2
0
        public override void OnInsert(object target, IEntityProperty property)
        {
            if (property.PropertyType != typeof(DateTime))
            {
                throw new ArgumentException("Property is not of type DateTime");
            }

            property.SetValue(target, DateTime.UtcNow);
        }
        /*=========================*/
        #endregion

        #region BindingList<T> overrides
        /*=========================*/

        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="item"></param>
        protected override void InsertItem(int index, EntityT item)
        {
            // Determine whether this is a valid item; duplicate it if it belongs to a different list
            if (item.ParentList != this)
            {
                item = ImportItem(item);
            }

            else if (item.DataState != EntityDataState.Deleted && item.DataState != EntityDataState.Detached)
            {
                throw new InvalidOperationException("Cannot add items that are already in the list.");
            }

            // Save original list
            StoreOriginals();

            // Create index entries, throw exceptions if non-unique
            Dictionary <IndexDefinition, IndexEntry> indexEntries = CreateIndexEntries(item);

            // Mark ordinals if property is available
            if (_ordProperty != null)
            {
                _ordProperty.SetValue(item, index);

                for (int i = index + 1; i < this.Count; i++)
                {
                    _ordProperty.SetValue(this[i], i);
                }
            }

            // Apply the indexes now
            ApplyIndexEntries(item, indexEntries);

            // Remove the item from the deleted list since we're re-adding it
            if (item.DataState == EntityDataState.Deleted)
            {
                item.DataState = item.HasValueChanges ? EntityDataState.Modified : EntityDataState.Unchanged;
            }

            // Insert the item
            base.InsertItem(index, item);
        }