/// <summary> /// Initializes a new instance of the <see cref="FieldChange"/> class. /// </summary> /// <param name="a">A.</param> /// <param name="property">The property.</param> /// <param name="foreignTable">The foreign table.</param> /// <param name="foreignFeildName">Name of the foreign feild.</param> /// <param name="foreignFeildKey">The foreign feild key.</param> public FieldChange(Audit a, string property, string foreignTable, string foreignFeildName, string foreignFeildKey) { //FieldChange x = new FieldChange(a, property); //todo:refactor CTSContext db = new CTSContext(); // this.ChangeDate = a.DateTime; UserProfile user = UserProfile.GetUserById(a.LoginID); this.ChangedBy = (user != null) ? user.UserName : "******"; this.FieldName = property; this.PreviousValue = a.OldValue; this.ChangedValue = a.NewValue; this.FieldName = property; var prevKey = Convert.ToInt32(this.PreviousValue); var CurrentKey = Convert.ToInt32(this.ChangedValue); //modified Banty:24/5/2013 from db.ExecuteStoreQuery to (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery //todo: var Prev = (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery<string>(" SELECT " + foreignFeildName + " as field FROM " + foreignTable + " WHERE " + foreignFeildKey + " = " + prevKey).FirstOrDefault(); //todo: var now = (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery<string>(" SELECT " + foreignFeildName + " as field FROM " + foreignTable + " WHERE " + foreignFeildKey + " = " + CurrentKey).FirstOrDefault(); ; // var Prev = db.AuditForeignFeild(foreignTable,foreignFeildName,prevKey,foreignFeildKey).SingleOrDefault(); // var now = db.AuditForeignFeild(foreignTable, foreignFeildName, CurrentKey, foreignFeildKey).SingleOrDefault(); //todo:if(Prev != null) //{ // this.PreviousValue = Prev.ToString(); // //this.PreviousValue = Prev.field; //} //if(now != null) //{ // this.ChangedValue = now.ToString(); //} }
/// <summary> /// Initializes a new instance of the <see cref="FieldChange"/> class. /// </summary> /// <param name="audit">The audit.</param> /// <param name="proprtyName">Name of the proprty.</param> public FieldChange(Audit audit, string proprtyName) { // this.ChangeDate = audit.DateTime; UserProfile user = UserProfile.GetUserById(audit.LoginID); this.ChangedBy = (user != null) ? user.UserName : "******"; this.FieldName = proprtyName; this.PreviousValue = audit.OldValue; this.ChangedValue = audit.NewValue; }