Example #1
0
        /// <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);
            CTSContext db = new CTSContext();

             //   this.ChangeDate = a.DateTime;
            BLL.UserProfile user = BLL.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
            var Prev = (db as IObjectContextAdapter).ObjectContext.ExecuteStoreQuery<string>(" SELECT " + foreignFeildName + " as field FROM " + foreignTable + " WHERE " + foreignFeildKey + " = " + prevKey).FirstOrDefault();
            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();

            if(Prev != null)
            {
                this.PreviousValue = Prev.ToString();
                //this.PreviousValue = Prev.field;
            }
            if(now != null)
            {
                this.ChangedValue = now.ToString();
            }
        }