//public bool CheckChangeChanges(TModel oldData, DynamicParameters newData)
        //{
        //    HasChanges = false;
        //    //start observer
        //    Diff = new DynamicParameters();

        //    //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;
        //            }
        //            string newValue = prop.GetValue(newData) == null ? string.Empty : prop.GetValue(newData).ToString();
        //            string oldValue = prop.GetValue(oldData) == null ? string.Empty : prop.GetValue(oldData).ToString();

        //            if (newValue != oldValue)
        //            {
        //                //setting the changed value in property for saving
        //                Diff.Add(prop.Name, prop.GetValue(newData));
        //                //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));
        //                changed_values.Add(row);
        //            }
        //        }

        //    }
        //    catch(Exception ex)
        //    {
        //        Bango.Base.Log.LogTrace.WriteErrorLog(ex.ToString());
        //    }

        //    if (HasChanges)
        //    {
        //        Changes.table_name = ModelService.GetTableName(oldData);
        //        Changes.changed_values = JsonConvert.SerializeObject(changed_values);
        //        Changes.activity_datetime = DateTime.Now;
        //        Changes.user_id = Bango.GetCurrentUserId();
        //        Changes.pkey_name = Changes.GetKeyPropertyInfo().Name;
        //    }
        //    return HasChanges;
        //}
        public bool CheckChangeChanges_old(TModel oldData, TModel newData)
        {
            HasChanges = false;
            //start observer
            var s = Snapshotter.Start(oldData);

            //merge new data into old data
            ModelService srvc         = new ModelService();
            TModel       oldDataClone = new TModel();

            srvc.CopyProperty(oldData, oldDataClone);
            bool status = srvc.Merge <TModel>(newData, oldData, GetIgnoreFields(ActivityType));

            //changes
            Diff = s.Diff();
            List <Dictionary <string, object> > changed_values = new List <Dictionary <string, object> >();

            if (Diff.ParameterNames.AsList <string>().Count > 0)
            {
                foreach (string name in Diff.ParameterNames.AsList <string>())
                {
                    Dictionary <string, object> row = new Dictionary <string, object>();
                    row.Add("field_name", name);
                    row.Add("old_value", oldDataClone.GetType().GetProperty(name).GetValue(oldDataClone));
                    row.Add("new_value", newData.GetType().GetProperty(name).GetValue(newData));
                    //row.Add("new_value", Diff.Get<string>(name));
                    changed_values.Add(row);
                }

                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.pkey_name = Changes.GetKeyPropertyInfo().Name;
                Changes.os_computer_name = HttpRequestHelper.GetClientHostName();
                Changes.os_ipaddress     = HttpRequestHelper.GetClientIpAddress();
                Changes.os_useragent     = HttpRequestHelper.GetClientBrowser();
                //  Changes.mac_address = HttpRequestHelper.GetMacAddress();
                HasChanges = true;
            }
            //if(changes.ParameterNames.le)
            return(HasChanges);
        }
        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);
        }