public bool CheckChangeChanges(TModel oldData, DynamicDictionary newData) { HasChanges = false; var s = Snapshotter.Start(oldData); //start observer Diff = new DynamicParameters(); ChangedValues = new ExpandoObject(); //merge new data into old data ModelService srvc = new ModelService(); TModel oldDataClone = new TModel(); srvc.CopyProperty(oldData, oldDataClone); List <string> ignoreFields = GetIgnoreFields(ActivityType); //bool status = srvc.Merge<TModel>(newData, oldData, GetIgnoreFields(ActivityType)); //changes //Diff = s.Diff(); List <Dictionary <string, object> > changed_values = new List <Dictionary <string, object> >(); try { foreach (PropertyInfo prop in oldData.GetType().GetProperties()) { if (ignoreFields.Contains <string>(prop.Name)) { continue; } if (!newData.ContainsKey(prop.Name)) { continue; } string newValue = newData.GetValue(prop.Name) == null ? string.Empty : newData.GetValue(prop.Name).ToString(); string oldValue = prop.GetValue(oldData) == null ? string.Empty : prop.GetValue(oldData).ToString(); if (newValue != oldValue) { //setting the changed value in property for saving //storing data for saving in change history. HasChanges = true; Dictionary <string, object> row = new Dictionary <string, object>(); row.Add("field_name", prop.Name); row.Add("old_value", oldDataClone.GetType().GetProperty(prop.Name).GetValue(oldDataClone)); //row.Add("new_value", newData.GetType().GetProperty(prop.Name).GetValue(newData)); row.Add("new_value", newData.GetValue(prop.Name)); changed_values.Add(row); prop.SetValue(oldData, ModelService.ChangeType(newData.GetValue(prop.Name), prop.PropertyType)); } } } catch (Exception ex) { Bango.Base.Log.LogTrace.WriteErrorLog(ex.ToString()); throw new Exception("Error while tracking changes."); } if (HasChanges) { Changes.table_name = ModelService.GetTableName(oldData); Changes.changed_values = JsonConvert.SerializeObject(changed_values); Changes.activity_datetime = DateTime.Now; Changes.user_id = SessionData.user_id; Changes.activity_type = ActivityType.ToString(); Changes.os_computer_name = HttpRequestHelper.GetClientHostName(); Changes.os_ipaddress = HttpRequestHelper.GetClientIpAddress(); Changes.os_useragent = HttpRequestHelper.GetClientBrowser(); // Changes.pkey_name = Changes.GetKeyPropertyInfo().Name; } Diff = s.Diff(); return(HasChanges); }