Example #1
0
        //Client Name End
        public virtual List <String> LoadAssignedRoles(DbConnect con, int user_id)
        {
            IEnumerable <DynamicDictionary> list = DbServiceUtility.ExecuteList(con, GetAllAssignedRolesQuery(user_id).ToString());
            List <string> rights = new List <string>();

            if (list != null)
            {
                foreach (DynamicDictionary dict in list)
                {
                    rights.Add(dict.GetValueAsString("role_id"));
                }
            }
            return(rights);
        }
Example #2
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);
        }