Exemple #1
0
        /// <summary>
        /// Saves the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="fireEvents">if set to <c>true</c> fire events.</param>
        /// <returns>The entity.</returns>
        public virtual TEntity Save(TEntity entity, bool fireEvents = true)
        {
            SavingEntityEventArgs args = null;

            if (fireEvents)
            {
                var existing = Get(GetId(entity));
                args = new SavingEntityEventArgs
                {
                    Entity = new BeforeAndAfter <object>
                    {
                        Before = existing,
                        After  = entity
                    }
                };

                Fluidity.OnSavingEntity(args);

                if (args.Cancel)
                {
                    return((TEntity)args.Entity.After);
                }

                entity = (TEntity)args.Entity.After;
            }

            entity = SaveImpl(entity);

            if (fireEvents)
            {
                Fluidity.OnSavedEntity(args);

                entity = (TEntity)args.Entity.After;
            }

            return(entity);
        }
        public object Save(object entity, bool fireEvents = true)
        {
            SavingEntityEventArgs args = null;

            if (fireEvents)
            {
                var existing = Get(entity.GetPropertyValue(_collection.IdProperty));
                args = new SavingEntityEventArgs
                {
                    Entity = new BeforeAndAfter <object>
                    {
                        Before = existing,
                        After  = entity
                    }
                };

                Fluidity.OnSavingEntity(args);

                if (args.Cancel)
                {
                    return(args.Entity.After);
                }

                entity = args.Entity.After;
            }

            Db.Save(args.Entity.After);

            if (fireEvents)
            {
                Fluidity.OnSavedEntity(args);

                entity = args.Entity.After;
            }

            return(entity);
        }
Exemple #3
0
 public static void OnSavingEntity(SavingEntityEventArgs args)
 {
     SavingEntity?.Invoke(null, args);
 }