Beispiel #1
0
        protected virtual ItemMovingEventArgs <T> OnItemAdding(T item)
        {
            var evArg = new ItemMovingEventArgs <T>(item);

            ItemAdding?.Invoke(this, evArg);
            return(evArg);
        }
Beispiel #2
0
 public virtual void AddNew <TEntity>(params TEntity[] values) where TEntity : class, new()
 {
     foreach (var entity in values ?? throw new ArgumentNullException(nameof(values)))
     {
         DataContext.Set <TEntity>().Add(entity);
         ItemAdding?.Invoke(entity);
     }
 }
Beispiel #3
0
        public void AddItem(IGrabableItem item, bool triggerEvent = true)
        {
            items.Add(item);

            if (triggerEvent)
            {
                ItemAdding?.Invoke(this, item);
            }
        }
Beispiel #4
0
        public virtual void AddOrUpdate <TEntity>(IEnumerable <TEntity> collection) where TEntity : class, new()
        {
            foreach (var entity in collection ?? throw new ArgumentNullException(nameof(collection)))
            {
                // Check to see if this is a new entity (by checking the key)
                if (IsNew(entity))
                {
                    DataContext.Set <TEntity>().Add(entity);
                    ItemAdding?.Invoke(entity);
                }
                else
                {
                    // Is this entity already attached?
                    var entry = GetEntryByKey(entity);
                    if (entry.Entity.GetHashCode() != entity.GetHashCode())                     // Objects are NOT the same!
                    {
                        throw new NotSupportedException("A different entity object with the same key already exists in the ChangeTracker");
                    }

                    entry.State = EntityState.Modified;
                    ItemModifing?.Invoke(entity);
                }
            }
        }
Beispiel #5
0
 public void OnItemAdded(ObservableListEventArgs <T> e)
 {
     ItemAdding?.Invoke(this, e);
     ItemAdded?.Invoke(this, e);
 }
Beispiel #6
0
        //public override void EndNew(int itemIndex) {
        //    //var item = Items[itemIndex];
        //    //NewItemCommited?.Invoke(item, itemIndex);
        //    base.EndNew(itemIndex);
        //}

        //protected override void SetItem(int index, T item) {
        //    base.SetItem(index, item);
        //}

        protected override void InsertItem(int index, T item)
        {
            ItemAdding?.Invoke(item, index);
            base.InsertItem(index, item);
        }