Пример #1
0
        public static DB.SYS_Log New <T>(String fieldName, String tableName, Int64 entityId, T oldValue, T newValue)
        {
            SYS_Log returnValue = new SYS_Log();

            returnValue.FieldName = fieldName;
            returnValue.TableName = tableName;
            returnValue.EntityId  = entityId;
            returnValue.OldValue  = oldValue.ToString();
            returnValue.NewValue  = newValue.ToString();

            return(returnValue);
        }
Пример #2
0
        internal static String Save(DB.SYS_Log entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntitySystemContext.GetEntityState(entry) == EntityState.Detached)
                {
                    dataContext.EntitySystemContext.SYS_Log.Add(entry);
                }

                Validation.ValidateEntity(dataContext.EntitySystemContext, entry);
            }
            catch (Validation.EntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Пример #3
0
        private void LogChanges(ChangeTracker dbChangeTracker)
        {
            foreach (EntityEntry entity in dbChangeTracker.Entries().Where(obj => { return(obj.State == EntityState.Modified || obj.State == EntityState.Deleted); }))
            {
                if (BL.ApplicationDataContext.NonProxyType(entity.GetType()) == typeof(DB.SYS_Log))
                {
                    continue;
                }

                //LogObject logObject = new LogObject();

                //logObject.EntityType = BL.ApplicationDataContext.NonProxyType(entity.Entity.GetType());

                //if (entity.State == EntityState.Added)
                //    logObject.Action = EntityState.Added.ToString();
                //else if (entity.State == EntityState.Modified)
                //    logObject.Action = EntityState.Modified.ToString();
                //else if (entity.State == EntityState.Deleted)
                //    logObject.Action = EntityState.Deleted.ToString();

                switch (entity.State)
                {
                case EntityState.Modified:

                    foreach (string propertyName in entity.CurrentValues.Properties.Select(l => l.Name))
                    {
                        DB.SYS_Log sysLog = BL.SYS.SYS_Log.New;
                        sysLog.EntityId  = Convert.ToInt64(entity.CurrentValues["Id"]);
                        sysLog.TableName = BL.ApplicationDataContext.NonProxyType(entity.Entity.GetType()).Name;

                        if (propertyName == "CreatedOn" || propertyName == "CreatedBy" || propertyName == "Title")
                        {
                            continue;
                        }

                        sysLog.FieldName = propertyName;

                        if (entity.CurrentValues[propertyName] == null && entity.OriginalValues[propertyName] == null)
                        {
                        }
                        else if (entity.CurrentValues[propertyName] != null && entity.OriginalValues[propertyName] == null)
                        {
                            sysLog.OldValue = "";
                            sysLog.NewValue = entity.CurrentValues[propertyName].ToString();
                            EntityController.SaveSYS_Log(sysLog, this);
                        }
                        else if (entity.CurrentValues[propertyName] == null && entity.OriginalValues[propertyName] != null)
                        {
                            sysLog.OldValue = entity.OriginalValues[propertyName].ToString();
                            sysLog.NewValue = "";
                            EntityController.SaveSYS_Log(sysLog, this);
                        }
                        else if (entity.CurrentValues[propertyName].ToString() != entity.OriginalValues[propertyName].ToString())
                        {
                            sysLog.OldValue = entity.OriginalValues[propertyName].ToString();
                            sysLog.NewValue = entity.CurrentValues[propertyName].ToString();
                            EntityController.SaveSYS_Log(sysLog, this);
                        }
                    }
                    break;

                case EntityState.Deleted:
                    //if (BL.ApplicationDataContext.NonProxyType(entity.Entity.GetType()) != typeof(DB.ITM_InventorySupplier))
                    //    throw new Exception("Deleting Entries not allowed in this system implement and archive");
                    break;
                }

                //if (entity.State == EntityState.Added || entity.State == EntityState.Modified)
                //{
                //    System.Xml.Linq.XDocument currentValues = new System.Xml.Linq.XDocument(new System.Xml.Linq.XElement(logObject.EntityType.Name));

                //    foreach (string propertyName in entity.CurrentValues.PropertyNames)
                //    {
                //        currentValues.Root.Add(new System.Xml.Linq.XElement(propertyName, entity.CurrentValues[propertyName]));
                //    }

                //    logObject.NewData = System.Text.RegularExpressions.Regex.Replace(currentValues.ToString(), @"\r\n+", " ");
                //}

                //if (entity.State == EntityState.Modified || entity.State == EntityState.Deleted)
                //{
                //    System.Xml.Linq.XDocument originalValues = new System.Xml.Linq.XDocument(new System.Xml.Linq.XElement(logObject.EntityType.Name));

                //    foreach (string propertyName in entity.OriginalValues.PropertyNames)
                //    {
                //        originalValues.Root.Add(new System.Xml.Linq.XElement(propertyName, entity.OriginalValues[propertyName]));
                //    }

                //    logObject.OldData = System.Text.RegularExpressions.Regex.Replace(originalValues.ToString(), @"\r\n+", " ");
                //}


                //auditTrailList.Add(auditObject);
            }
        }