Пример #1
0
        public static ChangeTracker UpdateData(this ChangeTracker changeTracker, ISessionApp appSession)
        {
            foreach (var entry in changeTracker.Entries().Where(entry => entry.Entity is EntityBase && entry.State != EntityState.Unchanged))
            {
                var date = DateTime.UtcNow.RemoverMilisSegundos();

                entry.Property("IdUsuarioAlteracao").CurrentValue = appSession.GetUserId();
                entry.Property("DataAlteracao").CurrentValue      = date;

                if (entry.State == EntityState.Added)
                {
                    entry.Property("IdUsuarioInclusao").CurrentValue = appSession.GetUserId();
                    entry.Property("DataInclusao").CurrentValue      = date;
                }
                else if (entry.State == EntityState.Modified)
                {
                    entry.Property("IdUsuarioInclusao").IsModified = false;
                    entry.Property("DataInclusao").IsModified      = false;

                    entry.Property("IdUsuarioAlteracao").CurrentValue = appSession.GetUserId();
                    entry.Property("DataAlteracao").CurrentValue      = DateTime.UtcNow.RemoverMilisSegundos();
                }
            }

            return(changeTracker);
        }
Пример #2
0
        protected MainController(INotificationService notificador,
                                 ISessionApp appSession)
        {
            _notificador = notificador;
            _appSession  = appSession;

            if (appSession.IsAuthenticated())
            {
                UsuarioId          = appSession.GetUserId();
                UsuarioAutenticado = true;
            }
        }