Exemplo n.º 1
0
        public bool InsertAudit(AuditModel Audit)
        {
            bool result = false;

            try
            {
                using (AuditEntities auditEntities = new AuditEntities())
                {
                    var config = new MapperConfiguration(
                        cfg =>
                    {
                        cfg.CreateMap <AuditModel, Audit>();
                    }
                        );

                    var mapper = config.CreateMapper();
                    var audit  = mapper.Map <Audit>(Audit);
                    auditEntities.Audits.Add(audit);
                    auditEntities.SaveChanges();
                }

                result = true;
            }
            catch (Exception ex)
            {
                var log = new Logger();
                log.LogError(Audit.UserID.ToString(), "DataSolutions.Data", "InsertAudit", ex.Message);
            }

            return(result);
        }
Exemplo n.º 2
0
        public List <AuditModel> GetLast10Audit(int UserID)
        {
            List <AuditModel> auditList = new List <AuditModel>();

            try
            {
                using (AuditEntities audit = new AuditEntities())
                {
                    var audits = (from a in audit.Audits
                                  where a.UserID == UserID
                                  orderby a.AuditDate descending
                                  select  new AuditModel
                    {
                        ActivityDescription = a.ActivityDescription,
                        AuditDate = a.AuditDate,
                        AuditID = a.AuditID,
                        UserID = a.UserID
                    }).Take(10);

                    auditList = audits.ToList();
                }
            }
            catch (Exception ex)
            {
                var log = new Logger();
                log.LogError(UserID.ToString(), "DataSolutions.Data", "InsertAudit", ex.Message);
            }

            return(auditList);
        }
Exemplo n.º 3
0
        private void BuildAuditForEntity(EntityEntry entry,
                                         Auditable isAudit,
                                         string username,
                                         AuditEntity auditEntity)
        {
            string id = entry.CurrentValues[isAudit.EntityIdPropertyName].ToString();

            var list = new List <AuditEntityProperty>();
            var type = entry.Entity.GetType();

            auditEntity.ActionId   = (int)entry.State;
            auditEntity.EntityName = type.Name;
            auditEntity.EntityId   = id;

            foreach (var property in entry.CurrentValues.Properties)
            {
                var    curVal = entry.CurrentValues[property.Name];
                object oldVal = null;

                if (entry.State == EntityState.Modified)
                {
                    oldVal = entry.OriginalValues[property.Name];
                }

                if (NotEqual(oldVal, curVal))
                {
                    list.Add(new AuditEntityProperty
                    {
                        PropertyName = property.Name,
                        OldValue     = oldVal == null ? null : oldVal.ToString(),
                        NewValue     = curVal == null ? null : curVal.ToString(),
                        AuditEntity  = auditEntity,
                    });
                }
            }

            auditEntity.AuditEntityProperties = list;
            AuditEntities.Add(auditEntity);
        }