Ejemplo n.º 1
0
        public async Task <bool> Create(AuditLogProperty AuditLogProperty)
        {
            AuditLogPropertyDAO AuditLogPropertyDAO = new AuditLogPropertyDAO();

            AuditLogPropertyDAO.Id         = AuditLogProperty.Id;
            AuditLogPropertyDAO.AppUserId  = AuditLogProperty.AppUserId;
            AuditLogPropertyDAO.Property   = AuditLogProperty.Property;
            AuditLogPropertyDAO.OldValue   = AuditLogProperty.OldValue;
            AuditLogPropertyDAO.NewValue   = AuditLogProperty.NewValue;
            AuditLogPropertyDAO.ClassName  = AuditLogProperty.ClassName;
            AuditLogPropertyDAO.ActionName = AuditLogProperty.ActionName;
            AuditLogPropertyDAO.Time       = AuditLogProperty.Time;
            DataContext.AuditLogProperty.Add(AuditLogPropertyDAO);
            await DataContext.SaveChangesAsync();

            AuditLogPropertyDAO.Id = AuditLogPropertyDAO.Id;
            await SaveReference(AuditLogPropertyDAO);

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> BulkMerge(List <AuditLogProperty> AuditLogProperties)
        {
            List <AuditLogPropertyDAO> AuditLogPropertyDAOs = new List <AuditLogPropertyDAO>();

            foreach (AuditLogProperty AuditLogProperty in AuditLogProperties)
            {
                AuditLogPropertyDAO AuditLogPropertyDAO = new AuditLogPropertyDAO();
                AuditLogPropertyDAO.Id         = AuditLogProperty.Id;
                AuditLogPropertyDAO.AppUserId  = AuditLogProperty.AppUserId;
                AuditLogPropertyDAO.Property   = AuditLogProperty.Property;
                AuditLogPropertyDAO.OldValue   = AuditLogProperty.OldValue;
                AuditLogPropertyDAO.NewValue   = AuditLogProperty.NewValue;
                AuditLogPropertyDAO.ClassName  = AuditLogProperty.ClassName;
                AuditLogPropertyDAO.ActionName = AuditLogProperty.ActionName;
                AuditLogPropertyDAO.Time       = AuditLogProperty.Time;
                AuditLogPropertyDAOs.Add(AuditLogPropertyDAO);
            }
            await DataContext.BulkMergeAsync(AuditLogPropertyDAOs);

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <bool> Update(AuditLogProperty AuditLogProperty)
        {
            AuditLogPropertyDAO AuditLogPropertyDAO = DataContext.AuditLogProperty.Where(x => x.Id == AuditLogProperty.Id).FirstOrDefault();

            if (AuditLogPropertyDAO == null)
            {
                return(false);
            }
            AuditLogPropertyDAO.Id         = AuditLogProperty.Id;
            AuditLogPropertyDAO.AppUserId  = AuditLogProperty.AppUserId;
            AuditLogPropertyDAO.Property   = AuditLogProperty.Property;
            AuditLogPropertyDAO.OldValue   = AuditLogProperty.OldValue;
            AuditLogPropertyDAO.NewValue   = AuditLogProperty.NewValue;
            AuditLogPropertyDAO.ClassName  = AuditLogProperty.ClassName;
            AuditLogPropertyDAO.ActionName = AuditLogProperty.ActionName;
            AuditLogPropertyDAO.Time       = AuditLogProperty.Time;
            await DataContext.SaveChangesAsync();

            await SaveReference(AuditLogPropertyDAO);

            return(true);
        }
Ejemplo n.º 4
0
        public async Task <List <AuditLogPropertyDAO> > CreateAuditLog(DataContext DataContext)
        {
            List <AuditLogPropertyDAO> AuditLogPropertyDAOs = new List <AuditLogPropertyDAO>();
            var modifiedEntities = DataContext.ChangeTracker.Entries()
                                   .Where(p => p.State == EntityState.Modified ||
                                          p.State == EntityState.Added ||
                                          p.State == EntityState.Deleted ||
                                          p.State == EntityState.Modified ||
                                          p.State == EntityState.Detached)
                                   .ToList();


            foreach (var change in modifiedEntities)
            {
                var type       = change.GetType();
                var entityName = type.Name;

                var EntityDisplayName = type.GetCustomAttributes(typeof(DisplayNameAttribute), true)
                                        .Select(x => ((DisplayNameAttribute)x).DisplayName)
                                        .DefaultIfEmpty(type.Name)
                                        .First();

                if (change.State == EntityState.Added)
                {
                    // Log Added
                }
                else if (change.State == EntityState.Modified)
                {
                    foreach (var prop in change.Entity.GetType().GetTypeInfo().DeclaredProperties)
                    {
                        if (!prop.GetGetMethod().IsVirtual)
                        {
                            var currentValue  = change.Property(prop.Name).CurrentValue;
                            var originalValue = change.Property(prop.Name).OriginalValue;
                            if (!Equals(originalValue, currentValue))
                            {
                                var attributes = prop.GetCustomAttributes(typeof(DisplayNameAttribute), false);
                                if (attributes != null && attributes.Length > 0)
                                {
                                    var displayName = (DisplayNameAttribute)attributes[0];
                                    AuditLogPropertyDAO AuditLogPropertyDAO = new AuditLogPropertyDAO();
                                    AuditLogPropertyDAO.Property   = displayName.ToString();
                                    AuditLogPropertyDAO.ActionName = AuditLogPropertyActionEnum.EDIT.Name;
                                    AuditLogPropertyDAO.OldValue   = originalValue.ToString();
                                    AuditLogPropertyDAO.NewValue   = currentValue.ToString();
                                    AuditLogPropertyDAO.Time       = StaticParams.DateTimeNow;
                                    AuditLogPropertyDAO.ClassName  = EntityDisplayName;
                                    DataContext.AuditLogProperty.Add(AuditLogPropertyDAO);
                                    AuditLogPropertyDAOs.Add(AuditLogPropertyDAO);
                                }
                            }
                        }
                    }
                }
                else if (change.State == EntityState.Deleted)
                {
                    AuditLogPropertyDAO AuditLogPropertyDAO = new AuditLogPropertyDAO();
                    AuditLogPropertyDAO.ActionName = AuditLogPropertyActionEnum.CREATE.Name;
                    AuditLogPropertyDAO.Time       = StaticParams.DateTimeNow;
                    AuditLogPropertyDAO.ClassName  = EntityDisplayName;
                    DataContext.AuditLogProperty.Add(AuditLogPropertyDAO);
                    AuditLogPropertyDAOs.Add(AuditLogPropertyDAO);
                }
            }
            return(AuditLogPropertyDAOs);
        }
Ejemplo n.º 5
0
 private async Task SaveReference(AuditLogPropertyDAO AuditLogPropertyDAO)
 {
 }