Пример #1
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var auditable = @event.Entity as IAuditableEntity;
            if (auditable == null)
            {
                return false;
            }

            string userUniqueId = string.Empty;

            var user = ApplicationContext.User;
            if (user != null)
            {
                var identity = ApplicationContext.User.Identity as ICoreIdentity;
                if (identity != null)
                {
                    userUniqueId = identity.Id;
                }
            }

            DateTime createdAt = DateTime.Now;

            this.Set(@event.Persister, @event.State, "CreatedBy", userUniqueId);
            this.Set(@event.Persister, @event.State, "UpdatedBy", userUniqueId);
            this.Set(@event.Persister, @event.State, "CreatedAt", createdAt);
            this.Set(@event.Persister, @event.State, "UpdatedAt", createdAt);

            auditable.CreatedBy = userUniqueId;
            auditable.UpdatedBy = userUniqueId;
            auditable.CreatedAt = createdAt;
            auditable.UpdatedAt = createdAt;

            return false;
        }
Пример #2
0
 /// <summary>
 /// Add the information related to The dates on where 
 /// the data was created on the database
 /// </summary>
 /// <param name="instance">the instance for the data to save</param>
 /// <returns>a false value</returns>
 public bool OnPreInsert(PreInsertEvent instance)
 {
     var moment = DateTime.Now;
     instance.SetDate(moment, "Added", instance.State);
     instance.SetDate(moment, "Modified", instance.State);
     return false;
 }
        /// <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 eventItem)
        {
            Trip trip = eventItem.Entity as Trip;
            if (null == trip)
            {
                return false;
            }

            if (ViolatesTripConstraint(eventItem.Session, trip.Observer.StaffCode, trip.TripNumber, trip.Id))
            {
                throw new Exception("Trip with this staff code/trip number already exists.");
            }

            // Mess with Departure/Return dates
            if (trip.DepartureDate.HasValue && !trip.DepartureDateOnly.HasValue)
            {
                // Set DateOnly to midnight
                trip.DepartureDateOnly = trip.DepartureDate.Value.Subtract(trip.DepartureDate.Value.TimeOfDay);
            }

            if (trip.ReturnDate.HasValue && !trip.ReturnDateOnly.HasValue)
            {
                // Set DateOnly to midnight
                trip.ReturnDateOnly = trip.ReturnDate.Value.Subtract(trip.ReturnDate.Value.TimeOfDay);
            }

            return false;
        }
Пример #5
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            SetAuditFields(@event.Entity as IAuditableEntity, "Insert");
            CommitAuditInfo(@event.Persister, @event.State, "CreateDate");

            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;
        }
Пример #7
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var timestamped = (@event.Entity as ITimestamped);
            if (!isValidEntity(timestamped)) return false;

            timestamped.Timestamp = new Timestamp();

            updateState(@event.Persister, @event.State, "Timestamp", timestamped.Timestamp);

            return false;
        }
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var entity = @event.Entity as EntityBase;
            if (entity == null)
                return false;

            entity.IsDeleted = false;
            entity.CreatedAt = DateTime.Now;
            Set(@event.Persister, @event.State, "CreatedAt", entity.CreatedAt);
            return false;
        }
 public bool OnPreInsert(PreInsertEvent @event)
 {
     var c = @event.Entity as IAuditInfo;
     if (c == null)
         return false;
     c.CreatedBy = sUsernameProvider.Username;
     Set(@event.Persister, @event.State, "CreatedBy", c.CreatedBy);
     c.CreatedOn = DateTime.Now;
     Set(@event.Persister, @event.State, "CreatedOn", c.CreatedOn);
     return false;
 }
        /// <summary>
        /// 엔티티를 처음 등록할 때, 엔티티의 UpdateTimestamp 속성 값이 없을 때, 현재 시각으로 설정합니다.
        /// </summary>
        /// <param name="event"></param>
        /// <returns></returns>
        public bool OnPreInsert(PreInsertEvent @event) {
            if(IsDebugEnabled)
                log.Debug("엔티티에 대해 PreInsertEvent를 수행합니다...");

            var entity = @event.Entity as IUpdateTimestampedEntity;

            // UpdateTimestamp 값을 사용자가 미리 지정했을 수도 있으므로 값이 없을 때에만 할당한다.
            if(entity != null && entity.UpdateTimestamp.HasValue == false)
                entity.UpdateTimestamp = GetCurrentTime();

            return false;
        }
Пример #11
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;
        }
Пример #12
0
 public bool OnPreInsert(PreInsertEvent e)
 {
     var auditable = e.Entity as IAuditable;
     if (auditable == null)
         return false;
     var time = DateTime.UtcNow;
     SetState(e.Persister, e.State, "Created", time);
     SetState(e.Persister, e.State, "Updated", time);
     auditable.Created = time;
     auditable.Updated = time;
     return false;
 }
Пример #13
0
 public bool OnPreInsert(PreInsertEvent @event)
 {
     var systemEntity = @event.Entity as SystemEntity;
     if (systemEntity != null)
     {
         DateTime now = CurrentRequestData.Now;
         SetCreatedOn(@event.Persister, @event.State, systemEntity, now);
         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;
 }
Пример #14
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            IModel owner = @event.Entity as IModel;

            if (owner == null || @event.Session.EntityMode != EntityMode.Poco)
            {
                return false;
            }

            Validate(owner);

            return false;
        }
Пример #15
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var createdEntity = @event.Entity as IAuditableEntity;

            if (createdEntity == null) return false;

            var datAndtime = DateTime.UtcNow;

            PersistAuditInfo(@event.Persister, @event.State, "CreateDate", datAndtime);

            createdEntity.CreateDate = datAndtime;

            return false;
        }
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var auditableEntity = @event.Entity as IEntityWithAuditing;
            if (auditableEntity == null)
                return false;

            auditableEntity.AuditingInfo = new AuditingInfo
            {
                CreatedBy = "Me",
                CreatedOn = DateTime.Now
            };
            Set(@event.Persister, @event.State, "AuditingInfo", auditableEntity.AuditingInfo);

            return false;
        }
        /// <summary>
        /// Return true if the operation should be vetoed
        /// </summary>
        /// <param name="event"/>
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var audit = @event.Entity as Entity;
            if (audit == null)
                return false;

            var time = DateTime.Now;
            Set(@event.Persister, @event.State, "CreatedOn", time);
            Set(@event.Persister, @event.State, "ModifiedOn", time);

            audit.CreatedOn = time;
            audit.ModifiedOn = time;

            return false;
        }
		public bool OnPreInsert(PreInsertEvent e)
		{
			if(e.Entity is DomainClass == false)
				return false;

			// this will join into the parent's transaction
			using (var session = e.Session.GetSession(EntityMode.Poco))
			{
				//should insert log record here
				session.Save(new LogClass());
				session.Flush();
			}

			return false;
		}
Пример #19
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            GetAuditProperties(@event.Entity);
             if (_auditProperties.IsEmpty()) return false;
             try {
            var sessionID = new Guid(ConfigurationManager.AppSettings["SessionID"]);
            var sessionSerice = Locator.Resolve<ISessionService>();
            var user = sessionSerice.GetUserAccount(sessionID);
            SetAuditProperties(@event, @event.Persister, @event.State, user, DateTime.Now);

            return false;
             }
             catch (Exception) {
            return false;
             }
        }
Пример #20
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var entity = @event.Entity as Entity;

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

            Set(@event.Persister, @event.State, @"CreatedBy", _actor);
            Set(@event.Persister, @event.State, @"UpdatedBy", _actor);

            entity.CreatedBy = _actor;
            entity.UpdatedBy = _actor;

            return false;
        }
Пример #21
0
        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, "ModifyDate", time);
            Set(@event.Persister, @event.State, "ModifyUser", name);

            audit.ModifyDate = time;
            audit.ModifyUser = name;

            return false;
        }
Пример #22
0
        public bool OnPreInsert(PreInsertEvent e)
        {
            var auditable = e.Entity as IAuditableEntity;
            if (auditable == null)
                return false;

            var name = (ApplicationContext.User != null && !string.IsNullOrEmpty(ApplicationContext.User.Identity.Name)) ? ApplicationContext.User.Identity.Name : "Unknown";

            Set(e.Persister, e.State, "CreatedBy", name);
            Set(e.Persister, e.State, "UpdatedBy", name);
            Set(e.Persister, e.State, "UpdatedAt", DateTime.UtcNow);

            auditable.CreatedBy = name;
            auditable.UpdatedBy = name;

            return false;
        }
        public bool OnPreInsert(PreInsertEvent @event)
        {
            IAuditableModel auditableModel = @event.Entity as IAuditableModel;
            if (auditableModel == null) return false;

            auditableModel.CreatedBy = System.Threading.Thread.CurrentPrincipal.Identity.Name;
            auditableModel.CreatedTime = DateTime.Now;
            auditableModel.UpdatedBy = auditableModel.CreatedBy;
            auditableModel.UpdatedTime = auditableModel.CreatedTime;

            Set(@event.Persister, @event.State, "CreatedTime", auditableModel.CreatedTime);
            Set(@event.Persister, @event.State, "CreatedBy", auditableModel.CreatedBy);
            Set(@event.Persister, @event.State, "UpdatedTime", auditableModel.UpdatedTime);
            Set(@event.Persister, @event.State, "UpdatedBy", auditableModel.UpdatedBy);

            return false;
        }
Пример #24
0
        public bool OnPreInsert(PreInsertEvent preInsertEvent)
        {
            var audit = preInsertEvent.Entity as IAuditable;

            if (audit == null)
                return false;

            var time = DateTime.UtcNow;
            var userid = CurrentUserId();

            Set(preInsertEvent.Persister, preInsertEvent.State, "CreatedOnUtc", time);
            Set(preInsertEvent.Persister, preInsertEvent.State, "CreatedBy", userid);

            preInsertEvent.Entity.GetType().GetMethod("ChangeCreatedBy", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(preInsertEvent.Entity, new object[] { userid });
            preInsertEvent.Entity.GetType().GetMethod("ChangeCreatedOnUtc", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(preInsertEvent.Entity, new object[] { time });

            return false;
        }
        /// <summary>
        /// Return true if the operation should be vetoed
        /// </summary>
        /// <param name="event"/>
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var entity = @event.Entity as ICreatedAndUpdatedProperty;

            if (entity == null)
                return false;

            var time = (entity.Created == DateTime.MinValue ?
                DateTime.Now : entity.Created);

            Set(@event.Persister, @event.State, "Updated", time);
            Set(@event.Persister, @event.State, "Created", time);

            entity.Updated = time;
            entity.Created = time;

            return false;
        }
Пример #26
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var tenantScoped = @event.Entity as ITenantScopedEntity;
            if (tenantScoped == null)
            {
                return false;
            }

            var tenant = ApplicationContext.User as TenantPrincipal;
            if (tenant == null)
            {
                throw new InternalException("No tenant principal in context");
            }

            this.Set(@event.Persister, @event.State, "TenantId", tenant.TenantId);

            tenantScoped.SetTenantId(tenant.TenantId);

            return false;
        }
        /// <inheritdoc/>
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var audit = @event.Entity as IAuditEntity;
            if (audit == null)
                return false;

            var time = DateTime.Now;

            Set(@event.Persister, @event.State, "Created", time);
            Set(@event.Persister, @event.State, "CreatedBy", CurrentUser);
            Set(@event.Persister, @event.State, "Updated", time);
            Set(@event.Persister, @event.State, "UpdatedBy", CurrentUser);

            audit.Created = time;
            audit.CreatedBy = CurrentUser;
            audit.Updated = time;
            audit.UpdatedBy = CurrentUser;

            return false;
        }
Пример #28
0
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var entity = @event.Entity as Entity;
            if (entity == null)
                return false;

            DateTime time = DateTime.Now;
            string name = GetUserId();

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

            entity.CreatedAt = time;
            entity.CreatedBy = name;
            //entity.UpdatedAt = null;
            //entity.UpdatedBy = null;

            return false;
        }
        public bool OnPreInsert(PreInsertEvent @event)
        {
            var audit = @event.Entity as IHaveAuditInformation;
            if (audit == null)
                return false;

            var time = DateTime.Now;
            var user = GetUser();

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

            audit.CreatedAt = time;
            audit.CreatedBy = user;
            audit.UpdatedAt = time;
            audit.UpdatedBy = user;

            return false;
        }
        //http://ayende.com/Blog/archive/2009/04/29/nhibernate-ipreupdateeventlistener-amp-ipreinserteventlistener.aspx
        public bool OnPreInsert(PreInsertEvent event_item)
        {
            Auditable audit = event_item.Entity as Auditable;
            if (audit == null)
            {
                return false;
            }

            DateTime? entered_date = DateTime.Now;
            DateTime? modified_date = DateTime.Now;
            string identity_of_updater = get_identity();

            store(event_item.Persister, event_item.State, "entered_date", entered_date);
            store(event_item.Persister, event_item.State, "modified_date", modified_date);
            store(event_item.Persister, event_item.State, "updating_user", identity_of_updater);
            audit.entered_date = entered_date;
            audit.modified_date = modified_date;
            audit.updating_user = identity_of_updater;

            return false;
        }