Exemplo n.º 1
0
        //public int Insert(DBConnection Connection, ROLEDC objROLEs)
        //{
        //    int insertCount = 0;
        //    //foreach (ROLEDC objROLE in objROLEs)
        //    //{
        //    insertCount = Insert(Connection, objROLEs);
        //   // }
        //    return insertCount;
        //}
        public int Insert(DBConnection Connection, ROLEDC objROLE)
        {
            int insertCount = 0;

            StringBuilder sql = new StringBuilder();

            sql.Append("proc_ROLESInsert");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);


            dbCommandWrapper.AddOutParameter("p_ROLE_ID", DbType.Int32, objROLE.ROLE_ID);
            dbCommandWrapper.AddInParameter("p_ROLE_NAME", DbType.String, objROLE.ROLE_NAME);
            dbCommandWrapper.AddInParameter("p_DESCRIPTION", DbType.String, objROLE.DESCRIPTION);
            dbCommandWrapper.AddInParameter("p_IS_RESTRICTED", DbType.Boolean, objROLE.IS_RESTRICTED);
            dbCommandWrapper.AddInParameter("p_STATUS", DbType.String, objROLE.STATUS);
            dbCommandWrapper.AddInParameter("p_CREATED_BY", DbType.Int32, objROLE.CREATED_BY);
            dbCommandWrapper.AddInParameter("p_MODIFIED_BY", DbType.Int32, objROLE.MODIFIED_BY);

            try
            {
                if (Connection.Transaction != null)
                {
                    insertCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand, Connection.Transaction);
                }
                else
                {
                    insertCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand);
                }
            }
            catch (Exception exp)
            {
                //Utilities.InsertIntoErrorLog("Error: ROLE INSERTION ", exp.Message + "\r\n" + exp.StackTrace, objROLE.MODIFIED_BY);
                objROLE.SetError(exp);
                throw exp;
            }
            objROLE.ROLE_ID = (int)dbCommandWrapper.DBCommand.Parameters["@p_ROLE_ID"].Value;
            return(insertCount);
        }
Exemplo n.º 2
0
        public int Update(DBConnection Connection, ROLEDC objROLE, bool updatePermissions)
        {
            int updateCount = 0;

            StringBuilder sql = new StringBuilder();

            sql.Append("proc_ROLESUpdate");

            DBCommandWarpper dbCommandWrapper = new DBCommandWarpper(Connection.dataBase.GetStoredProcCommand(sql.ToString()), Connection);


            dbCommandWrapper.AddInParameter("p_ROLE_ID", DbType.Int32, objROLE.ROLE_ID);
            dbCommandWrapper.AddInParameter("p_ROLE_NAME", DbType.String, objROLE.ROLE_NAME);
            dbCommandWrapper.AddInParameter("p_DESCRIPTION", DbType.String, objROLE.DESCRIPTION);
            dbCommandWrapper.AddInParameter("p_IS_RESTRICTED", DbType.Boolean, objROLE.IS_RESTRICTED);
            dbCommandWrapper.AddInParameter("p_STATUS", DbType.String, objROLE.STATUS);
            dbCommandWrapper.AddInParameter("p_MODIFIED_BY", DbType.Int32, objROLE.MODIFIED_BY);
            dbCommandWrapper.AddInParameter("p_lock_counter", DbType.Int32, objROLE.LOCK_COUNTER);

            try
            {
                if (Connection.Transaction != null)
                {
                    updateCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand, Connection.Transaction);
                }
                else
                {
                    updateCount = Connection.dataBase.ExecuteNonQuery(dbCommandWrapper.DBCommand);
                }

                if (updateCount == 0)
                {
                    objROLE.IsDirty = IsDirty = true;
                    throw new Exception(Constants.ConcurrencyMessageSingleRow);
                }
            }
            catch (Exception exp)
            {
                //Utilities.InsertIntoErrorLog("Error: ROLE UPDATE ", exp.Message + "\r\n" + exp.StackTrace, objROLE.MODIFIED_BY);
                objROLE.SetError(exp);
                throw exp;
            }

            if (updatePermissions && objROLE.PERMISSIONS.Count > 0)
            {
                DataTable dtPermissions = new DataTable();
                dtPermissions.Columns.Add("ROLE_ID");
                dtPermissions.Columns.Add("SCREEN_ID");
                dtPermissions.Columns.Add("PERMISSION_TYPE_ID");
                dtPermissions.Columns.Add("PERMISSION_TYPE");
                dtPermissions.Columns.Add("PERMISSION_TITLE");
                dtPermissions.Columns.Add("GENERAL_EDIT_ACCESS_TYPE");
                dtPermissions.Columns.Add("VIEW_ACCESS_GENERAL");
                dtPermissions.Columns.Add("EDIT_ACCESS");

                foreach (ROLES_PERMISSIONDC permission in objROLE.PERMISSIONS)
                {
                    dtPermissions.Rows.Add(permission.ROLE_ID,
                                           permission.SCREEN_ID,
                                           permission.PERMISSION_TYPE_ID,
                                           permission.PERMISSION_TYPE,
                                           permission.PERMISSION_TITLE,
                                           permission.GENERAL_EDIT_ACCESS_TYPE,
                                           permission.VIEW_ACCESS_GENERAL,
                                           permission.EDIT_ACCESS);
                }

                sql.Clear();
                sql.Append("proc_ROLESUpdateROLES_PERMISSIONS");

                SqlDatabase database = (SqlDatabase)Connection.dataBase;

                DbCommand cmd = database.GetStoredProcCommand(sql.ToString());

                database.AddInParameter(cmd, "p_ROLE_ID", SqlDbType.Int, objROLE.ROLE_ID);
                database.AddInParameter(cmd, "@p_ROLE_PERMISSIONS_TABLE", SqlDbType.Structured, dtPermissions);
                try
                {
                    if (Connection.Transaction != null)
                    {
                        updateCount = database.ExecuteNonQuery(cmd, Connection.Transaction);
                    }
                    else
                    {
                        updateCount = database.ExecuteNonQuery(cmd);
                    }

                    if (updateCount == 0)
                    {
                        objROLE.IsDirty = IsDirty = true;
                        throw new Exception(Constants.ConcurrencyMessageSingleRow);
                    }
                }
                catch (Exception exp)
                {
                    //Utilities.InsertIntoErrorLog("Error: ROLES_PERMISSIONS UPDATE ", exp.Message + "\r\n" + exp.StackTrace, objROLE.MODIFIED_BY);
                    objROLE.SetError(exp);
                    throw exp;
                }
            }

            return(updateCount);
        }