public String Audit(BaseModel obj)//Make sure that obj contain iD { string Changes = ""; if (obj != null) { string name = obj.GetType().Name; name.Substring(0, name.Length - 5); Int64 id = Int64.Parse(PropertyUtils.GetValue(obj, name.Substring(0, name.Length - 5) + "iD").ToString()); BaseModel oldObject = null; oldObject = FindByPK(id); Changes = obj.CompareTo(oldObject); } return(Changes); }
public virtual string CompareTo(BaseModel model) { StringBuilder result = new StringBuilder(); string modelName = this.GetType().Name; string fID = modelName.Substring(0, modelName.Length - 5) + "iD"; string[] fields = GetAuditFields(); if (model == null) { foreach (string field in fields) { if (field.Equals(fID)) { continue; } object value1 = PropertyUtils.GetValue(this, field); result.Append(string.Format("- {0}: {1}<br>", field, value1)); } } else { if (this.GetType() != model.GetType()) { return("None"); } foreach (string field in fields) { if (field.Equals(fID)) { continue; } object value1 = PropertyUtils.GetValue(this, field); object value2 = PropertyUtils.GetValue(model, field); if (!value1.Equals(value2)) { result.Append(string.Format("- {0}: {1} -> {2}<br>", field, value2, value1)); } } } return(result.Length > 0 ? result.ToString() : "None"); }