private List <AuditLogs> GetAddedProperties(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]; } foreach (var property in entry.CurrentValues.Properties) { AuditLogs auditInfo = new AuditLogs(); 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.Action = action; if (!string.IsNullOrEmpty(query)) { int n; bool isNumeric = int.TryParse(Convert.ToString(entry.CurrentValues[property]), out n); if (entry.CurrentValues[property] != null) { GetForeignTableData dt = null; dt = _context.ExecuteSqlQuery <GetForeignTableData>(_context, query.Replace("@Id", isNumeric == true ? Convert.ToString(entry.CurrentValues[property]) : "'" + Convert.ToString(entry.CurrentValues[property]) + "'")).FirstOrDefault(); //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; } } else { auditInfo.NewValue = entry.CurrentValues[property] != null && Convert.ToString(entry.CurrentValues[property]) != string.Empty ? Convert.ToString(entry.CurrentValues[property]) : null; } auditInfo.AuditLogColumnId = ColumnId; auditInfo.CreatedById = userId; auditInfo.ScreenName = screenName; auditInfo.CreatedDate = DateTime.UtcNow; // UTC Time for manage Time according to time zone auditInfo.ParentInfo = parentInfo; 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); }