private List <AuditLogs> GetModifiedProperties(EntityEntry entry, string screenName, string action, Nullable <int> patientId, Nullable <int> userId, string parentInfo, TokenModel token) { List <AuditLogs> auditInfoList = new List <AuditLogs>(); string TableName = GetTableName(entry); string[] entityName = TableName.Split('_'); if (entityName.Count() == 2) { TableName = entityName[0]; } PropertyValues dbValues = entry.GetDatabaseValues(); foreach (var property in entry.OriginalValues.Properties) { string newVal = Convert.ToString(entry.CurrentValues[property]).Trim(); string oldVal = Convert.ToString(dbValues[property]).Trim(); AuditLogs auditInfo = new AuditLogs(); if (oldVal != null && !oldVal.Equals(newVal)) { int TableId = _context.AuditLogTable.Where(p => p.TableName == TableName && p.IsActive == true && p.OrganizationID == token.OrganizationID).Select(p => p.Id).FirstOrDefault(); var ColumnId = _context.AuditLogColumn.Where(p => p.AuditLogTableId == TableId && p.ColumnName == property.Name && p.IsActive == true).Select(p => p.Id).FirstOrDefault(); string query = _context.AuditLogColumn.Where(p => p.AuditLogTableId == TableId && p.ColumnName == property.Name && p.IsActive == true).Select(p => p.Query).FirstOrDefault(); if (ColumnId != 0) { auditInfo.PatientId = patientId; auditInfo.AuditLogColumnId = ColumnId; auditInfo.ScreenName = screenName; auditInfo.CreatedDate = DateTime.UtcNow; // UTC Time for manage Time according to time zone auditInfo.CreatedById = userId; auditInfo.Action = action; auditInfo.ParentInfo = parentInfo; if (!string.IsNullOrEmpty(query)) { GetForeignTableData dt = null; int n; bool isNumeric = int.TryParse(Convert.ToString(entry.CurrentValues[property]), out n); if (entry.CurrentValues[property] != null) { dt = _context.ExecuteQuery <GetForeignTableData>(query.Replace("@Id", isNumeric == true ? Convert.ToString(entry.CurrentValues[property]) : "'" + Convert.ToString(entry.CurrentValues[property]) + "'"), 0).FirstOrDefault(); if (dt != null) { auditInfo.NewValue = Convert.ToString(dt.Value); } } else { auditInfo.NewValue = null; } isNumeric = int.TryParse(Convert.ToString(dbValues[property]), out n); if (dbValues[property] != null) { dt = _context.ExecuteQuery <GetForeignTableData>(query.Replace("@Id", isNumeric == true ? Convert.ToString(dbValues[property]) : "'" + Convert.ToString(dbValues[property]) + "'"), 0).FirstOrDefault(); if (dt != null) { auditInfo.OldValue = Convert.ToString(dt.Value); } } else { auditInfo.OldValue = null; } } else { auditInfo.OldValue = dbValues[property] != null && Convert.ToString(dbValues[property]) != string.Empty ? Convert.ToString(dbValues[property]) : null; auditInfo.NewValue = entry.CurrentValues[property] != null && Convert.ToString(entry.CurrentValues[property]) != string.Empty ? Convert.ToString(entry.CurrentValues[property]) : null; } auditInfo.EncryptionCode = CommonMethods.GetHashValue( screenName.Trim() + action.Trim() + (auditInfo.OldValue != null ? auditInfo.OldValue : string.Empty) + (auditInfo.NewValue != null ? auditInfo.NewValue : string.Empty) + (auditInfo.AuditLogColumnId != null ? Convert.ToString(auditInfo.AuditLogColumnId) : string.Empty) + (auditInfo.CreatedById != null ? Convert.ToString(auditInfo.CreatedById) : string.Empty) + (Convert.ToString(auditInfo.CreatedDate)) + (patientId != null ? Convert.ToString(patientId) : string.Empty) + token.IPAddress.Trim() + Convert.ToString(token.OrganizationID) + Convert.ToString(token.LocationID)); auditInfoList.Add(auditInfo); } } } return(auditInfoList); }