예제 #1
0
        public override ResponseModel Insert(DbConnect con, DynamicDictionary item)
        {
            UserModel model = new UserModel();

                        //setting the client_id before inserting record if client_id field exists.
                        if(model.GetType().GetProperty("client_id") != null)
            {
                if (item.GetValueAsInt("client_id") == null)
                {
                    item.Add("client_id", SessionData.client_id);
                }
                else
                {
                    item.Add("client_id", item.GetValueAsInt("client_id"));
                }
            }

            string new_file_name = item.GetValueAsString("new_file_name");

            if (new_file_name != "")
            {
                string reltive_path = "temp/";
                item.SetValue("photo_path", reltive_path + new_file_name);
            }
            ResponseModel resp = base.Insert(con, item);

            if (resp.success)
            {
                int user_id = (int)((DynamicDictionary)resp.data).GetValueAsInt("id");
                resp.data = user_id;
                return(resp);
            }
            return(resp);
        }
예제 #2
0
        public static object ToObject(DataRow row)
        {
            dynamic obj = new DynamicDictionary();

            foreach (DataColumn c in row.Table.Columns)
            {
                obj.SetValue(c.ColumnName, row[c.ColumnName]);
                //obj.//
            }
            return((object)obj);
            //foreach (PropertyInfo prop in this.GetType().GetProperties())
            //{
            //    if (dr.Table.Columns.Contains(prop.Name))
            //    {
            //        if (dr[prop.Name].GetType() == typeof(DBNull))
            //        {
            //            prop.SetValue(this, null);
            //        }
            //        else
            //        {
            //            dynamic
            //            prop.SetValue(this, ChangeType(dr[prop.Name], prop.PropertyType));
            //            prop.SetValue(this, Convert.ChangeType(dr[prop.Name], prop.PropertyType));
            //        }

            //    }
            //}
        }
예제 #3
0
        public static DynamicDictionary PushValidationErros(DynamicDictionary soruce, DynamicDictionary destination)
        {
            foreach (string s in soruce.KeyList)
            {
                if (destination.ContainsKey(s))
                {
                    List <string> msgs = new List <string>();
                    if (destination.GetValue(s).GetType() == typeof(List <string>))
                    {
                        msgs = (List <string>)destination.GetValue(s); //soruce
                    }
                    else
                    {
                        msgs.Add(destination.GetValue(s).ToString());
                    }

                    if (soruce.GetValue(s).GetType() == typeof(List <string>))
                    {
                        List <string> n = (List <string>)soruce.GetValue(s);
                        msgs.AddRange(n);
                    }
                    else
                    {
                        msgs.Add(soruce.GetValue(s).ToString());
                    }
                    destination.SetValue(s, msgs);
                }
                else
                {
                    destination.Add(s, soruce.GetValue(s));
                }
            }
            return(destination);
        }
예제 #4
0
        public virtual ResponseBase DeleteChildItems(DbConnect con, string parentColumnName, TKey id)
        {
            DynamicDictionary filter = new DynamicDictionary();

            filter.SetValue(parentColumnName, id);
            filter.SetValue("client_id", SessionData.client_id);
            //TODO : by shakti
            // need to make a function that will only list the less fields for quickly processing.
            IEnumerable <dynamic> tt = Service.SearchRepo.GetSearchItems(filter, -1, 20, null);

            foreach (dynamic i in tt)
            {
                TKey         del_id = Conversion.ToDynamicDictionary(i).GetValue <TKey>("id");
                ResponseBase r      = Service.Delete(con, del_id);
                if (!r.success)
                {
                    return(r);
                }
            }
            return(new ResponseBase(true, "Records Deleted Successfully."));
        }
예제 #5
0
        //public override MyroCommand AfterBindingParameter(SearchScenario searchFor, DbConnect con, MyroCommand cmd, DynamicDictionary data_param, bool count = false, string tableAlias = null)
        //{
        //    //Myro.Base.List.DynamicDictionary sessionData = MyApp.LoadSessionDataForClient();
        //    //string role_id = sessionData.GetValueAsString("assigned_role_ids").Replace("[", "").Replace("]", "").Replace(@"""", "");
        //    User.UserService srvc = new User.UserService();
        //    string role_id = Newtonsoft.Json.JsonConvert.SerializeObject(srvc.LoadAssignedRoles(con, (int)SessionData.user_id)); ;
        //    role_id = role_id.Replace("[", "").Replace("]", "").Replace(@"""", "");

        //    string[] lst_rols = role_id.Split(',');
        //    bool rol_exists = lst_rols.Contains("1"); //not "Administrator"


        //    if (rol_exists==false) //not "Administrator"
        //    {
        //        if (role_id.Trim().Length > 0)
        //            data_param.Add("id", role_id);
        //    }

        //    MyroCommand cmd1 = cmd;

        //    if (data_param.ContainsKey("id"))
        //    {
        //        MyroCommand test = new MyroCommand(MyroCommandTypes.SqlBuilder);

        //        cmd1.Template = test.SqlBuilder.AddTemplate(string.Format(@"
        //                    {0}
        //                    AND c.id IN (WITH RECURSIVE roles(role_id) as (
        //                      SELECT assigned_role_id role_id
        //                            FROM RBAC_USER_ROLES
        //                            where is_deleted = false AND status = true AND user_id = {1}
        //                     UNION ALL
        //                      SELECT c.assigned_role_id role_id
        //                      FROM rbac_role_roles as  c
        //                       JOIN roles nd ON c.role_id = nd.role_id
        //                                    AND c.is_deleted = false AND c.status = true
        //                    )
        //                    SELECT DISTINCT role_id FROM roles ) ", cmd.FinalSql.Replace("@status", "true"),  SessionData.user_id ));
        //    }

        //    //Todo:Pending Task 01 Jun 2016 Shivashwor ...
        //    //cmd1 = DbServiceUtility.BindParameter(cmd, _model.GetType().GetProperty("id"), data_param, "c", SearchTypes.IN_Search); //IS NOT NULL
        //    return cmd1;
        //}

        public override BangoCommand AfterBindingParameter(SearchScenario searchFor, DbConnect con, BangoCommand cmd, DynamicDictionary data_param, bool count = false, string tableAlias = null)
        {
            //Myro.Base.List.DynamicDictionary sessionData = MyApp.LoadSessionDataForClient();
            //string role_id = sessionData.GetValueAsString("assigned_role_ids").Replace("[", "").Replace("]", "").Replace(@"""", "");
            User.UserService srvc    = new User.UserService();
            string           role_id = Newtonsoft.Json.JsonConvert.SerializeObject(srvc.LoadAssignedRoles(con, (int)SessionData.user_id));;

            role_id = role_id.Replace("[", "").Replace("]", "").Replace(@"""", "");

            string[] lst_rols   = role_id.Split(',');
            bool     rol_exists = lst_rols.Contains("1"); //not "Administrator"


            if (rol_exists == false) //not "Administrator"
            {
                if (role_id.Trim().Length > 0)
                {
                    data_param.SetValue("id", role_id);
                }
            }

            BangoCommand cmd1 = cmd;

            if (data_param.ContainsKey("id"))
            {
                // data_param.Remove("id");
                BangoCommand test = new BangoCommand(MyroCommandTypes.SqlBuilder);
                cmd1.Template = cmd1.SqlBuilder.AddTemplate(string.Format(@"  
                            {0} 
                            AND c.id >= (WITH RECURSIVE roles(role_id) as (
		                            SELECT assigned_role_id role_id 
                                    FROM RBAC_USER_ROLES 
                                    where is_deleted = false AND status = true AND user_id = {1}
	                            UNION ALL
		                            SELECT c.assigned_role_id role_id
		                            FROM rbac_role_roles as  c			
			                            JOIN roles nd ON c.role_id = nd.role_id
                                            AND c.is_deleted = false AND c.status = true
                            )
                            SELECT DISTINCT role_id FROM roles ) ", cmd.FinalSql.Replace("@status", "true"), SessionData.user_id));


                ///  cmd1.FinalParameters.AddDynamicParams(cmd.FinalParameters.ParameterNames);
            }

            //Todo:Pending Task 01 Jun 2016 Shivashwor ...
            //cmd1 = DbServiceUtility.BindParameter(cmd, _model.GetType().GetProperty("id"), data_param, "c", SearchTypes.IN_Search); //IS NOT NULL
            return(cmd1);
        }
예제 #6
0
        public static List <DynamicDictionary> ToDictionaryArray(DataTable dt)
        {
            List <DynamicDictionary> rows = new List <DynamicDictionary>();
            DynamicDictionary        row;

            foreach (DataRow dr in dt.Rows)
            {
                row = new DynamicDictionary();
                foreach (DataColumn col in dt.Columns)
                {
                    row.SetValue(col.ColumnName.ToLower(), dr[col]);
                }
                rows.Add(row);
            }
            return(rows);
        }
예제 #7
0
        DynamicDictionary set_json_Data(JToken data)
        {
            DynamicDictionary item = new DynamicDictionary();

            foreach (var r in data)
            {
                Newtonsoft.Json.Linq.JProperty pp = (Newtonsoft.Json.Linq.JProperty)r;

                if (pp.Count > 1)
                {
                    set_json_Data((JToken)pp);
                }
                else
                {
                    item.SetValue(pp.Name, pp.Value);
                }
            }

            return(item);
        }
예제 #8
0
        public async Task <HttpResponseMessage> PostFile()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string temp_root = FileBox.GetWebAppRoot() + "temp\\" + SessionData.client_id + "\\";
            string temp_url  = "//temp//" + SessionData.client_id + "//";

            if (!System.IO.Directory.Exists(temp_root))
            {
                System.IO.Directory.CreateDirectory(temp_root);
            }

            MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(temp_root);
            DynamicDictionary data = new DynamicDictionary();
            ResponseModel     resp = new ResponseModel(false, data);

            try
            {
                StringBuilder sb = new StringBuilder(); // Holds the response body
                // Read the form data and return an async task.
                var bodyparts = await Request.Content.ReadAsMultipartAsync(provider);

                //rename the file to proper-name

                // This illustrates how to get the form data.
                foreach (var key in provider.FormData.AllKeys)
                {
                    foreach (var val in provider.FormData.GetValues(key))
                    {
                        data.Add(key, val);
                    }
                }

                //for logo upload
                string logo_name = data.GetValueAsString("logo_name");
                string extension = string.Empty;

                if (logo_name != "")
                {
                    #region for logo upload
                    string basePath = FileBox.GetWebAppRoot() + "filebox\\CommonInput\\logo\\" + SessionData.client_id + "\\";
                    if (!System.IO.Directory.Exists(basePath))
                    {
                        System.IO.Directory.CreateDirectory(basePath);
                    }

                    //check if file already exist and delete if exist
                    string[] Logo_path = Directory.GetFiles(basePath, logo_name + ".*");
                    string[] filepath  = Directory.GetFiles(basePath, "*.*");
                    if (Logo_path.Length > 0)
                    {
                        System.IO.File.Delete(Logo_path[0]);
                    }
                    //check if file already exist and delete if exist

                    foreach (var file in provider.FileData)
                    {
                        string[] arr = file.Headers.ContentDisposition.FileName.Trim('"').Split('.');
                        if (arr.Length >= 1)
                        {
                            extension = "." + arr[arr.Length - 1];
                        }

                        System.IO.File.Move(file.LocalFileName, basePath + logo_name + extension);
                        data.Add("temp_file_url", basePath + logo_name + extension);
                    }
                    #endregion
                }
                else
                {
                    string url = HttpContext.Current.Request.Url.ToString().Substring(0, HttpContext.Current.Request.Url.ToString().IndexOf("/api/"));
                    // This illustrates how to get the file names for uploaded files.
                    string new_file_name = "";  // System.DateTime.Today.ToString("yyyymmddhhmmss") + "_" + getRandomID() + "_" + SessionData.user_id;
                    foreach (var file in provider.FileData)
                    {
                        FileInfo fileInfo = new FileInfo(file.LocalFileName);
                        string[] arr      = file.Headers.ContentDisposition.FileName.Trim('"').Split('.');

                        if (arr.Length >= 1)
                        {
                            extension = "." + arr[arr.Length - 1];
                        }

                        new_file_name = fileInfo.Name;

                        if (data.ContainsKey("temp_file_path"))
                        {
                            data.SetValue("temp_file_path", temp_root + new_file_name + extension);
                        }
                        else
                        {
                            data.Add("temp_file_path", temp_root + new_file_name + extension);
                        }

                        if (data.ContainsKey("file_name"))
                        {
                            data.SetValue("file_name", new_file_name + extension);
                        }
                        else
                        {
                            data.Add("file_name", new_file_name + extension);
                        }

                        //mime_type_id
                        if (data.ContainsKey("mime_type_id"))
                        {
                            data.SetValue("mime_type_id", extension);
                        }
                        else
                        {
                            data.Add("mime_type_id", extension);
                        }

                        if (data.ContainsKey("file_size_bytes"))
                        {
                            data.SetValue("file_size_bytes", fileInfo.Length);
                        }
                        else
                        {
                            data.Add("file_size_bytes", fileInfo.Length);
                        }

                        data.Add("temp_file_url", url + temp_url + new_file_name + extension);
                        data.Add("temp_file_url", temp_url + new_file_name + extension);

                        System.IO.File.Move(file.LocalFileName, temp_root + new_file_name + extension);
                    }
                }
                resp.success = true;
                resp.message = "File uploaded successfully";
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(resp))
                });
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
예제 #9
0
        public override ResponseModel Update(int?id, DynamicDictionary item)
        {
            string        message = string.Empty;
            bool          success = false;
            object        data    = item;
            ResponseModel resp    = new ResponseModel();
            UserModel     Model   = new UserModel();

            LoadItemAfterSave = true;
            using (DbConnect con = new DbConnect())
            {
                con.DB.BeginTransaction();
                try
                {
                    string new_file_name  = item.GetValueAsString("new_file_name");
                    string user_file_name = item.GetValueAsString("userfilename");
                    string relative_path  = "temp/";
                    if (user_file_name == null)
                    {
                        if (new_file_name != null)
                        {
                            item.SetValue("photo_path", relative_path + new_file_name);
                        }
                    }
                    else
                    {
                        if (new_file_name != "")
                        {
                            item.SetValue("photo_path", relative_path + new_file_name);
                        }
                        else
                        {
                            item.SetValue("photo_path", "");
                            string filePath = FileBox.GetWebAppRoot();
                            if (System.IO.File.Exists(filePath + user_file_name)) //if file exists than delete.
                            {
                                System.IO.File.Delete(filePath + user_file_name);
                            }
                        }
                    }
                    if (SessionData.client_id == 1)
                    {
                        CheckClientID = false;
                    }

                    resp = base.Update(id, item);

                    #region User Profile Window
                    if (resp.success && item.GetValueAsString("userProfile") == "true")
                    {
                        string file_name = item.GetValueAsString("new_file_name");
                        string filePath  = FileBox.GetWebAppRoot() + "temp/";
                        int?   photo_id  = item.GetValueAsInt("photo_id");
                        if (file_name == "")
                        {
                            var photoPath = item.GetValueAsString("user_file_name");
                            if (photoPath == "")
                            {
                                return(null);
                            }
                            if (System.IO.File.Exists(filePath + new_file_name)) //if file exists than delete.
                            {
                                System.IO.File.Delete(filePath + new_file_name);
                            }

                            int?tax_photo_id = item.GetValueAsInt("photo_id");
                            item.SetValue("photo_path", "");
                            resp = base.Update(id, item);
                        }
                        else
                        {
                            if (photo_id == 0)
                            {
                                item.SetValue("photo_path", relative_path + new_file_name);
                            }
                            else
                            {
                                item.SetValue("photo_path", relative_path + new_file_name);
                            }
                            resp = base.Update(id, item);
                        }
                    }
                    #endregion
                    else
                    {
                    }
                    if (resp.success)
                    {
                        con.DB.CommitTransaction();
                        message = "Data added successfully.";
                        success = true;
                        if (resp.success)
                        {
                            DynamicDictionary respdata        = (DynamicDictionary)resp.data;
                            string            confirmpassword = respdata.GetValueAsString("confirmpassword");
                            if (item.GetValueAsString("userProfile") == "" || item.GetValueAsString("userProfile") == null)
                            {
                                if (confirmpassword == "" || confirmpassword == null)
                                {
                                    int user_id = (int)((DynamicDictionary)resp.data).GetValueAsInt("id");
                                    resp.data = user_id;
                                    return(resp);
                                }
                            }
                        }
                        return(resp);
                    }
                    else
                    {
                        con.DB.RollbackTransaction();

                        if (resp.validation_errors.GetCount() > 0)
                        {
                            message = string.Join(",", resp.error_code);
                        }
                        else
                        {
                            message = "Data add failed, please try again later.";
                        }
                    }
                }
                catch (Exception)
                {
                    con.DB.RollbackTransaction();
                    message = "Data add failed, Rollback Transaction.";
                }
            }
            return(new ResponseModel(success, item.GetValue("photo_id"), message));
        }
예제 #10
0
        public virtual bool Update(DbConnect con, TKey id, DynamicDictionary data)
        {
            //pull old data
            TModel oldData            = new TModel();
            ITable <TModel, TKey> tbl = con.GetModelTable <TModel, TKey>();

            oldData = tbl.Get(id);
            //checking if the data is editable by current login or not
            if (CheckClientID)
            {
                if (ValidateForClientData(oldData) == false)
                {
                    return(false);
                }
            }


            ChangeHistoryHelper <TModel> chngHlpr = null;

            chngHlpr = new ChangeHistoryHelper <TModel>(AuditActivityTypes.UPDATE);
            //if CREATED_BY, CREATED_on field exists then update those fields
            PropertyInfo by = oldData.GetType().GetProperty("updated_by");

            if (by != null)
            {
                data.SetValue("updated_by", SessionData.user_id);
            }
            PropertyInfo on = oldData.GetType().GetProperty("updated_on");

            if (on != null)
            {
                data.SetValue("updated_on", DateTime.Now);
            }



            dynamic cloned = data.Clone();

            chngHlpr.CheckChangeChanges(oldData, data);
            //if no changes then return true
            if (chngHlpr.Diff.ParameterNames.Count() == 0)
            {
                return(true);
            }

            int?savedId = null;

            //chngHlpr.Diff.Add("id", id, DbType.Int32, ParameterDirection.Input);
            DynamicParameters where = new DynamicParameters();
            where.Add("id", id, DbServiceUtility.GetDbType(typeof(TKey)));
            if (CheckClientID)
            {
                PropertyInfo client_id = oldData.GetType().GetProperty("client_id");
                if (client_id != null)
                {
                    where.Add("client_id", SessionData.client_id, DbServiceUtility.GetDbType(client_id.PropertyType));
                }
            }
            try
            {
                savedId = tbl.Update(where, chngHlpr.Diff);

                if (TrackChanges)
                {
                    //save the changes
                    chngHlpr.LogChanges(con);
                }
            }
            catch (Npgsql.NpgsqlException ex)
            {
                LogTrace.WriteErrorLog(ex.ToString());
                LogTrace.WriteDebugLog(string.Format("SQL which gave exception:\r{0}", ex.Routine));
                throw ex;
            }
            if (savedId > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #11
0
        public virtual bool SoftDelete(DbConnect con, TKey id)
        {
            Is_Child_Records_Exists = false; //Default child record off
            //pull old data
            TModel oldData            = new TModel();
            ITable <TModel, TKey> tbl = con.GetModelTable <TModel, TKey>();

            oldData = tbl.Get(id);
            //checking if the data is editable by current login or not
            if (CheckClientID)
            {
                if (ValidateForClientData(oldData) == false)
                {
                    return(false);
                }
            }
            TableDetailAttribute tableDatail = oldData.GetTableDetail();

            //09 feb 2016  Foreign key refrence table data exists or not checke..
            #region todo:shivahwor
            StringBuilder Sql = new StringBuilder();
            Sql.AppendFormat(@"
                    SELECT 
                --tc.table_schema, tc.constraint_name, 
                tc.table_name, kcu.column_name
                --,ccu.table_name AS foreign_table_name, ccu.column_name AS foreign_column_name
                    FROM information_schema.table_constraints tc
                    JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name
                    JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name
                    WHERE constraint_type = 'FOREIGN KEY'
                    AND ccu.table_name='{0}' ", tableDatail.Name);

            IEnumerable <DynamicDictionary> foreignkey_Table = DbServiceUtility.ExecuteList(con, Sql.ToString());

            Sql.Length = 0;
            DynamicDictionary rec = null;
            if (foreignkey_Table != null)
            {
                foreach (DynamicDictionary item in foreignkey_Table)
                {
                    object tbl_Name = item.GetValue("table_name");
                    object col_name = item.GetValue("column_name");

                    if (Sql.Length > 0)
                    {
                        Sql.AppendLine("\n\t UNION ALL ");
                    }

                    Sql.AppendFormat(" SELECT 1 from {0} Where {1}={2}  AND is_deleted ='F' ", tbl_Name.ToString(), col_name.ToString(), id);
                }
                rec = DbServiceUtility.ExecuteItem(con, Sql.ToString());
            }

            if (rec != null)
            {
                if (rec.KeyList.Count > 0)
                {
                    Is_Child_Records_Exists = true;     //if child records exists than do not remove...
                    return(false);
                }
            }

            #endregion

            //data = new TModel();
            DynamicDictionary            data_param = new DynamicDictionary();
            ChangeHistoryHelper <TModel> chngHlpr   = null;
            chngHlpr = new ChangeHistoryHelper <TModel>(AuditActivityTypes.SOFTDELETE);
            //if CREATED_BY, CREATED_on field exists then update those fields
            PropertyInfo by = oldData.GetType().GetProperty("deleted_by");
            if (by != null)
            {
                data_param.SetValue("deleted_by", SessionData.user_id);
                //by.SetValue(data, Bango.GetCurrentUserId());
            }
            PropertyInfo on = oldData.GetType().GetProperty("deleted_on");
            if (on != null)
            {
                //on.SetValue(data, DateTime.Now);
                data_param.SetValue("deleted_on", DateTime.Now);
            }

            PropertyInfo uq_code = oldData.GetType().GetProperty("deleted_uq_code");
            if (on != null)
            {
                //on.SetValue(data, DateTime.Now);

                data_param.SetValue("deleted_uq_code", DateTime.Now.ToString("MMddHHmmss"));
            }

            PropertyInfo is_deleted = oldData.GetType().GetProperty(tableDatail.DeleteFlagField);
            if (is_deleted != null)
            {
                //is_deleted.SetValue(data, true);
                data_param.SetValue(tableDatail.DeleteFlagField, true);
            }

            chngHlpr.CheckChangeChanges(oldData, data_param);
            //chngHlpr.Diff.Add("id", id, DbType.Int32, ParameterDirection.Input);
            DynamicParameters where = new DynamicParameters();
            where.Add("id", id);
            if (CheckClientID)
            {
                PropertyInfo client_id = oldData.GetType().GetProperty("client_id");
                if (client_id != null)
                {
                    where.Add("client_id", SessionData.client_id);
                }
            }
            try
            {
                int?savedId = tbl.Update(where, chngHlpr.Diff);

                if (TrackChanges)
                {
                    //save the changes
                    chngHlpr.LogChanges(con);
                }
            }
            catch (Npgsql.NpgsqlException ex)
            {
                LogTrace.WriteErrorLog(ex.ToString());
                LogTrace.WriteDebugLog(string.Format("SQL which gave exception:\r{0}", ex.Routine));
                throw ex;
            }

            return(true);
        }
예제 #12
0
        public virtual bool Insert(DbConnect con, DynamicDictionary data)
        {
            //create empty object
            TModel empty = new TModel();
            ChangeHistoryHelper <TModel> chngHlpr = null;

            chngHlpr = new ChangeHistoryHelper <TModel>(AuditActivityTypes.INSERT);
            PropertyInfo key = Models.ModelService.GetKeyPropertyInfo(empty);

            if (data.ContainsKey(key.Name))
            {
                data.Remove(key.Name);
            }
            //if CREATED_BY, CREATED_on field exists then update those fields
            PropertyInfo by = empty.GetType().GetProperty("created_by");

            if (by != null)
            {
                data.SetValue("created_by", SessionData.user_id);
            }
            PropertyInfo on = empty.GetType().GetProperty("created_on");

            if (on != null)
            {
                data.SetValue("created_on", DateTime.Now);
            }
            if (CheckClientID)
            {
                PropertyInfo client_id = empty.GetType().GetProperty("client_id");
                if (client_id != null)
                {
                    if (!data.ContainsKey("client_id"))
                    {
                        data.SetValue("client_id", SessionData.client_id);
                    }
                }
            }

            chngHlpr.CheckChangeChanges(new TModel(), data);
            ITable <TModel, int?> tbl = con.GetModelTable <TModel>();
            int?id = null;

            try
            {
                id = tbl.Insert(chngHlpr.Diff);
                //set the primary key in the object

                if (key != null)
                {
                    data.SetValue(key.Name, id);
                }

                if (TrackChanges)
                {
                    // chngHlpr.Changes.pkey_value = Convert.ToString(id);
                    //save the changes
                    chngHlpr.LogChanges(con);
                }
            }
            catch (Npgsql.NpgsqlException ex)
            {
                LogTrace.WriteErrorLog(ex.ToString());
                LogTrace.WriteDebugLog(string.Format("sql which gave exception:\r{0}", ex.Routine));
                throw ex;
            }
            if (id > 0)
            {
                return(true);
            }
            return(false);
        }