public static PaymentMethodCollection LoadForGroup(Int32 groupId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + PaymentMethod.GetColumnNames("ac_PaymentMethods"));
            selectQuery.Append(" FROM ac_PaymentMethods, ac_PaymentMethodGroups");
            selectQuery.Append(" WHERE ac_PaymentMethods.PaymentMethodId = ac_PaymentMethodGroups.PaymentMethodId");
            selectQuery.Append(" AND ac_PaymentMethodGroups.GroupId = @groupId");
            selectQuery.Append(" AND StoreId = @storeId");
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@groupId", System.Data.DbType.Int32, groupId);
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            //EXECUTE THE COMMAND
            PaymentMethodCollection results = new PaymentMethodCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        PaymentMethod paymentMethod = new PaymentMethod();
                        PaymentMethod.LoadDataReader(paymentMethod, dr);
                        results.Add(paymentMethod);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
        public static PaymentMethodCollection  LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + PaymentMethod.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_PaymentMethods");
            string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria;

            selectQuery.Append(whereClause);
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());
            //EXECUTE THE COMMAND
            PaymentMethodCollection results = new PaymentMethodCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        PaymentMethod paymentMethod = new PaymentMethod();
                        PaymentMethod.LoadDataReader(paymentMethod, dr);
                        results.Add(paymentMethod);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
Exemple #3
0
        public static PaymentMethodCollection LoadForUser(int userId, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //LOAD THE PAYMENT METHODS FOR THE STORE
            PaymentMethodCollection allMethods = PaymentMethodDataSource.LoadForStore(sortExpression);
            //LOAD THE USER TO OBTAIN ROLES
            User user = UserDataSource.Load(userId);
            //CREATE FILTERED LIST OF PAYMENT METHODS
            PaymentMethodCollection filteredMethods = new PaymentMethodCollection();

            foreach (PaymentMethod method in allMethods)
            {
                if (method.UserHasAccess(user))
                {
                    filteredMethods.Add(method);
                }
            }
            return(filteredMethods);
        }