private void SaveLog(IStatelessSession session, TermLog entity) { if (session == null) return; using (var tx = session.BeginTransaction()) { var currentEmployee = ApplicationCache.Get<Entity>(Global.LoginEmployee); if (currentEmployee != null) entity.AlterEmployeeId = currentEmployee.Id; session.Insert(entity); tx.Commit(); } }
public void OnPostDelete(PostDeleteEvent @event) { var entity = default(Term); if (@event.TryCatchEntity(ref entity)) { var statelessSession = @event.Persister.Factory.OpenStatelessSession(); var log = new TermLog { EmployeeId = entity.GetSnapshotValue<Guid>("EmployeeId"), Action = "D", Type = entity.GetType().Name, Name = entity.Text, Category = _alterWay, OldTime = FormatTime(entity.Start, entity.End), NewTime = null, Remark = _batchAlteringComments }; SaveLog(statelessSession, log); entity.EndEdit(); } }
public void OnPostUpdate(PostUpdateEvent @event) { var entity = default(Term); if (@event.TryCatchEntity(ref entity)) { var statelessSession = @event.Persister.Factory.OpenStatelessSession(); var start = entity.GetSnapshotValue<DateTime>("Start"); var end = entity.GetSnapshotValue<DateTime>("End"); var locked = entity.GetSnapshotValue<bool>("Locked"); if (start == entity.Start && end == entity.End && locked == entity.Locked) // no changed return; //var length = (entity.End - entity.Start).TotalMinutes; //var oldtime = (end - start).TotalMinutes; var log = new TermLog { SourceId = entity.Id, EmployeeId = entity.GetSnapshotValue<Guid>("EmployeeId"), Type = entity.GetType().Name, Name = entity.Text, Category = _alterWay, OldTime = FormatTime(start, end), NewTime = FormatTime(entity.Start, entity.End), Remark = _batchAlteringComments }; log.Action = entity.GetAction(); SaveLog(statelessSession, log); entity.EndEdit(); } }