/// <summary>
        ///
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public bool OnPreInsert(PreInsertEvent evt)
        {
            var index = Array.IndexOf(evt.Persister.PropertyNames, "FechaAlta");

            if (index >= 0 && evt.Entity.GetType().Namespace.StartsWith(MODEL_NAMESPACE))
            {
                evt.State[index] = VerCfg.RevisionTimestampGetter.Get(evt.Session.Auditer().GetCurrentRevision(false));
                evt.Entity.GetType()
                .GetProperties()
                .First(x => x.Name.CompareTo("FechaAlta") == 0)
                .SetValue(evt.Entity, evt.State[index]);
                evt.Entity.GetType()
                .GetProperties()
                .First(x => x.Name.CompareTo("FechaModificacion") == 0)
                .SetValue(evt.Entity, null);
                evt.Entity.GetType()
                .GetProperties()
                .First(x => x.Name.CompareTo("FechaBaja") == 0)
                .SetValue(evt.Entity, null);
                GetAuditedProperties(evt.Entity.GetType().GetProperties()).ToList().ForEach(x =>
                {
                    var value = x.GetValue(evt.Entity, null);
                    value.GetType()
                    .GetProperties()
                    .First(y => y.Name.CompareTo("FechaModificacion") == 0)
                    .SetValue(value, evt.State[index]);
                });
            }
            return(false);
        }
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var entity = (Entity)@event.Entity;

            Validator.ValidateObject(entity, new ValidationContext(entity, null, null));
            return(false);
        }
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var audit = @event.Entity as IHaveAuditInformation;

            if (audit == null)
            {
                return(false);
            }


            var time = DateTime.Now;

            //var name = WindowsIdentity.GetCurrent().Name;

            Set(@event.Persister, @event.State, "CreatedAt", time);
            Set(@event.Persister, @event.State, "UpdatedAt", time);
            //Set(@event.Persister, @event.State, "CreatedBy", name);
            //Set(@event.Persister, @event.State, "UpdatedBy", name);

            audit.CreatedAt = time;
            //audit.CreatedBy = name;
            audit.UpdatedAt = time;
            //audit.UpdatedBy = name;

            return(false);
        }
示例#4
0
 public static IEnumerable <PropertyEntry> ToPropertyEntry(
     this PreInsertEvent @event)
 {
     return(@event.State
            .Select((t, i) => @event.Persister.PropertyNames[i])
            .Select((name, i) => new NHibernatePropertyEntry(name, false, null, @event.State, i)));
 }
示例#5
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var systemEntity = @event.Entity as SystemEntity;

            if (systemEntity != null)
            {
                DateTime now = CurrentRequestData.Now;

                if (systemEntity.CreatedOn == DateTime.MinValue)
                {
                    SetCreatedOn(@event.Persister, @event.State, systemEntity, now);
                }

                if (systemEntity.UpdatedOn == DateTime.MinValue)
                {
                    SetUpdatedOn(@event.Persister, @event.State, systemEntity, now);
                }

                if (systemEntity is SiteEntity && (systemEntity as SiteEntity).Site == null)
                {
                    SetSite(@event.Persister, @event.State, systemEntity as SiteEntity, CurrentRequestData.CurrentSite);
                }
            }
            return(false);
        }
示例#6
0
        public bool OnPreInsert(PreInsertEvent e)
        {
            var i = e.Entity as ICreateAuditable <T>;

            if (i != null)
            {
                if (i.CreatedBy != null)
                {
                    i.CreatedBy = GetEntity(e.Session);
                }
                SetCreated(e.Persister, e.State, i);
            }

            var u = e.Entity as IModifyAuditable <T>;

            if (u != null)
            {
                if (u.ModifiedBy != null)
                {
                    u.ModifiedBy = GetEntity(e.Session);
                }
                SetModified(e.Persister, e.State, u);
            }
            return(false);
        }
示例#7
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var audit = @event.Entity as IAuditableEntity;

            if (audit != null)
            {
                try
                {
                    var time = DateTime.Now;
                    var name = Thread.CurrentPrincipal.Identity.Name;

                    Set(@event.Persister, @event.State, "CreatedAt", time);
                    Set(@event.Persister, @event.State, "CreatedBy", name);
                    Set(@event.Persister, @event.State, "UpdatedAt", time);
                    Set(@event.Persister, @event.State, "UpdatedBy", name);

                    audit.CreatedAt = time;
                    audit.CreatedBy = name;
                    audit.UpdatedAt = time;
                    audit.UpdatedBy = name;
                }
                catch (Exception)
                {
                    //NOP
                }
            }
            return(false);
        }
示例#8
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            Set(@event.Persister, @event.State, "CreateDate", DateTime.UtcNow);

            int idIndex = GetPropertyIndex(@event.Persister, "Id");

            if (idIndex >= 0 && @event.Persister.GetPropertyType("Id")
                .ReturnedClass == typeof(Guid))
            {
                // Create a new Guid if one was not assigned by client
                if (Get <Guid>(@event.Persister, @event.State, "Id") == default(Guid))
                {
                    Guid newGuid = Guid.NewGuid();
                    Set(@event.Persister, @event.State, "Id", newGuid);

                    // TODO: Need to be verified that this step provides the aggregate's Id
                    // to derived classes that about to be inserted (e.g. EdOrg -> School).
                    // The derived class should have the same Id value in the table.
                    var aggregateRoot = @event.Entity as AggregateRootWithCompositeKey;

                    if (aggregateRoot != null)
                    {
                        aggregateRoot.Id = newGuid;
                    }
                }
            }

            return(false);
        }
 /// <summary>
 /// Called when [pre insert].
 /// </summary>
 /// <param name="e">The e.</param>
 /// <returns></returns>
 public bool OnPreInsert(PreInsertEvent e)
 {
     if (e.Entity != null && IsAuditable(e.Entity))
     {
         InsertDeleteAuditLog((Entity <int>)e.Entity, e.Session, AuditType.Insert);
     }
     return(false);
 }
示例#10
0
 public async Task <bool> OnPreInsertAsync(PreInsertEvent e, CancellationToken cancellationToken)
 {
     if (e.Entity is IEntity entity)
     {
         await entity.BeforeSave(new ChangeTrackerArgs(e.State, null, e.Persister.PropertyNames, false)).ConfigureAwait(false);
     }
     return(false);
 }
 private bool SetCreationProps(PreInsertEvent @event)
 {
     if (@event.Entity is Resume candidate)
     {
         return(true);
     }
     return(false);
 }
示例#12
0
 public async Task <bool> OnPreInsertAsync(
     PreInsertEvent @event,
     CancellationToken cancellationToken
     )
 {
     cancellationToken.ThrowIfCancellationRequested();
     return(await Task.FromResult(OnPreInsert(@event)));
 }
示例#13
0
        public static IEnumerable <PropertyEntry> ToPropertyEntry(
            this PreInsertEvent @event)
        {
            var entityType = NHibernateUtil.GetClass(@event.Entity);

            return(@event.State
                   .Select((t, i) => @event.Persister.PropertyNames[i])
                   .Select((name, i) => new NHibernatePropertyEntry(entityType.GetProperty(@event.Persister.PropertyNames[i]), false, null, @event.State, i)));
        }
 public bool OnPreInsert(PreInsertEvent @event)
 {
     if (@event.Entity is ValidatableObject)
     {
         var entity = @event.Entity;
         Validator.ValidateObject(entity, CreateValidationContext(@event, entity), true);
     }
     return(false);
 }
 public bool OnPreInsert(PreInsertEvent @event)
 {
     if (@event.Entity is ValidatableObject)
     {
         var entity = (Entity)@event.Entity;
         Validator.ValidateObject(entity, new ValidationContext(entity, null, null), true);
     }
     return false;
 }
示例#16
0
 public static bool TryCatchEntity <T>(this PreInsertEvent @event, ref T entity)
 {
     if (@event.Entity is T)
     {
         entity = (T)@event.Entity;
         return(true);
     }
     return(false);
 }
示例#17
0
        public bool OnPreInsert(
            PreInsertEvent @event)
        {
            var properties = @event.ToPropertyEntry().ToList();

            Raise(@event, typeof(BeforeAddedEntityDomainEvent <>), @event.Entity, properties);

            return(false);
        }
 public bool OnPreInsert(PreInsertEvent @event)
 {
     if (@event.Entity is ValidatableObject)
     {
         var entity = @event.Entity;
         Validator.ValidateObject(entity, CreateValidationContext(@event, entity), true);
     }
     return false;
 }
示例#19
0
        public bool OnPreInsert(PreInsertEvent e)
        {
            if (_logger != null)
            {
                _logger.Insert(e.Entity as IEntity);
            }

            return(false);
        }
        public static void UpdateState(this PreInsertEvent @event, string propertyName, object propertyValue)
        {
            int index = @event.Persister.GetPropertyIndex(@event.Entity, propertyName);

            if (index >= 0)
            {
                @event.Persister.SetPropertyValue(@event.Entity, index, propertyValue, EntityMode.Poco);
                @event.State[index] = propertyValue;
            }
        }
示例#21
0
        public async Task <bool> OnPreInsertAsync(
            PreInsertEvent @event,
            CancellationToken cancellationToken)
        {
            var properties = @event.ToPropertyEntry().ToList();

            await RaiseAsync(@event, typeof(BeforeAddedEntityDomainEvent <>), @event.Entity, properties);

            return(false);
        }
示例#22
0
        public bool OnPreInsert(PreInsertEvent evt)
        {
            Entity entity = evt.Entity as Entity;

            entity.Builder   = GetUserId();
            entity.BuildTime = DateTime.Now;
            SetState(evt.Persister, evt.State, "Builder", entity.Builder);
            SetState(evt.Persister, evt.State, "BuildTime", entity.BuildTime);
            return(false);
        }
        private bool SetCreationProps(PreInsertEvent @event)
        {
            var folder = @event.Entity as Folder;

            if (folder != null)
            {
                folder.CreationDate = DateTime.Now;
                //folder.CreationAuthor = Locator.GetService<UserRepository>().GetCurrentUser();
            }
            return(false);
        }
示例#24
0
    public bool OnPreInsert(PreInsertEvent args)
    {
        var auditable = args.Entity as IAuditable;

        if (auditable != null)
        {
            Set(x => auditable.Creator, args.Persister.PropertyNames, auditable, args.State, SecurityManager.Identity);
            Set(x => auditable.DateAdded, args.Persister.PropertyNames, auditable, args.State, TwentyClock.Now);
        }
        return(false);
    }
    public bool OnPreInsert(PreInsertEvent @event)
    {
        var entity = @event.Entity as Entity;

        if (entity.UserId == 0)
        {
            entity.UserId = entity.ServerId;
            Set(@event.Persister, @event.State, "UserId", entity.UserId);
        }

        return(false);
    }
示例#26
0
        public bool OnPreInsert(PreInsertEvent ev)
        {
            if (!(ev.Entity is IHasCreationDate entity))
            {
                return(false);
            }
            var createdAt = DateTime.UtcNow;

            Set(ev.Persister, ev.State, "Created", createdAt);
            entity.Created = createdAt;
            return(false);
        }
示例#27
0
 public bool OnPreInsert(PreInsertEvent @event)
 {
     if (@event.Entity is Entity <ConnectionConfigurer> entity)
     {
         var persist = entity.OnPreInsert();
         foreach (var propertyName in @event.Persister.PropertyNames)
         {
             @event.State[Array.IndexOf(@event.Persister.PropertyNames, propertyName)] = @event.Entity.GetType().GetRuntimeProperties().SingleOrDefault(p => p.Name == propertyName)?.GetValue(@event.Entity);
         }
         return(!persist);
     }
     return(false);
 }
示例#28
0
        public bool OnPreInsert(PreInsertEvent ev)
        {
            ISystemInfo entity = ev.Entity as ISystemInfo;

            if (entity != null)
            {
                var currentDate = DateTime.Now;
                entity.Created = entity.Modified = currentDate;
                SetState(ev.Persister, ev.State, ModificationDatePropertyName, currentDate);
                SetState(ev.Persister, ev.State, CreationDatePropertyName, currentDate);
            }
            return(false);
        }
 public bool OnPreInsert(PreInsertEvent @event)
 {
     if (@event.Entity is IHaveAuditInformation audit)
     {
         var now = DateTime.Now;
         Set(@event.Persister, @event.State, nameof(IHaveAuditInformation.Created), now);
         Set(@event.Persister, @event.State, nameof(IHaveAuditInformation.LastModified), now);
         audit.Created      = now;
         audit.LastModified = now;
     }
     CheckDateTimeWithinSqlRange(@event.Persister, @event.State);
     return(false);
 }
        public bool OnPreInsert(PreInsertEvent insertEvent)
        {
            var rootFinder = insertEvent.Entity as ICanFindMyAggregateRoot;

            if (rootFinder == null)
            {
                return(false);
            }

            insertEvent.Session.Lock(rootFinder.MyRoot, LockMode.Force);

            return(false);
        }
示例#31
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            //This runs ok when running againts SQL Server
            //but if we run against other database it will fail
            SqlConnection connection = (SqlConnection)@event.Session.ConnectionManager.GetConnection();

            var tableName = ((ILockable)@event.Persister).RootTableName.ToLower();

            Log(@event, @event.State, null, tableName, connection);

            connection.Dispose();
            return(false);
        }
示例#32
0
        // Called before inserting an item in the data store.
        // Return true to cancel an insert operation.
        public bool OnPreInsert(PreInsertEvent @event)
        {
            if (!(@event.Entity is IAuditable audit))
            {
                return(false);
            }

            var utcNow = DateTime.UtcNow;

            SetState(@event.Persister, @event.State, nameof(IAuditable.CreatedUtc), utcNow);
            audit.CreatedUtc = utcNow;
            return(false);
        }
 public bool OnPreInsert(PreInsertEvent @event)
 {
     return true;
 }