Example #1
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);
        }
 public static PaymentMethod Load(Int32 paymentMethodId)
 {
     return(PaymentMethodDataSource.Load(paymentMethodId, true));
 }
 public static PaymentMethodCollection LoadForGroup(Int32 groupId, int maximumRows, int startRowIndex)
 {
     return(PaymentMethodDataSource.LoadForGroup(groupId, maximumRows, startRowIndex, string.Empty));
 }
 public static PaymentMethodCollection LoadForGroup(Int32 groupId, string sortExpression)
 {
     return(PaymentMethodDataSource.LoadForGroup(groupId, 0, 0, sortExpression));
 }
 public static PaymentMethodCollection LoadForGroup(Int32 groupId)
 {
     return(PaymentMethodDataSource.LoadForGroup(groupId, 0, 0, string.Empty));
 }
Example #6
0
        /// <summary>
        /// Saves this PaymentMethod object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        public virtual SaveResult Save()
        {
            if (this.IsDirty)
            {
                Database database     = Token.Instance.Database;
                bool     recordExists = true;

                //SET EMPTY STOREID TO CURRENT CONTEXT
                if (this.StoreId == 0)
                {
                    this.StoreId = Token.Instance.StoreId;
                }
                if (this.PaymentMethodId == 0)
                {
                    recordExists = false;
                }

                if (this.OrderBy < 0)
                {
                    this.OrderBy = PaymentMethodDataSource.GetNextOrderBy();
                }

                if (recordExists)
                {
                    //verify whether record is already present
                    StringBuilder selectQuery = new StringBuilder();
                    selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_PaymentMethods");
                    selectQuery.Append(" WHERE PaymentMethodId = @PaymentMethodId");
                    using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()))
                    {
                        database.AddInParameter(selectCommand, "@PaymentMethodId", System.Data.DbType.Int32, this.PaymentMethodId);
                        if ((int)database.ExecuteScalar(selectCommand) == 0)
                        {
                            recordExists = false;
                        }
                    }
                }

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_PaymentMethods SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", PaymentInstrumentId = @PaymentInstrumentId");
                    updateQuery.Append(", PaymentGatewayId = @PaymentGatewayId");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE PaymentMethodId = @PaymentMethodId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@PaymentMethodId", System.Data.DbType.Int32, this.PaymentMethodId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@PaymentInstrumentId", System.Data.DbType.Int16, this.PaymentInstrumentId);
                        database.AddInParameter(updateCommand, "@PaymentGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.PaymentGatewayId));
                        database.AddInParameter(updateCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_PaymentMethods (StoreId, Name, PaymentInstrumentId, PaymentGatewayId, OrderBy)");
                    insertQuery.Append(" VALUES (@StoreId, @Name, @PaymentInstrumentId, @PaymentGatewayId, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@PaymentMethodId", System.Data.DbType.Int32, this.PaymentMethodId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@PaymentInstrumentId", System.Data.DbType.Int16, this.PaymentInstrumentId);
                        database.AddInParameter(insertCommand, "@PaymentGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.PaymentGatewayId));
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._PaymentMethodId = result;
                    }
                }
                this.SaveChildren();

                //OBJECT IS DIRTY IF NO RECORDS WERE UPDATED OR INSERTED
                this.IsDirty = (result == 0);
                if (this.IsDirty)
                {
                    return(SaveResult.Failed);
                }
                else
                {
                    return(recordExists ? SaveResult.RecordUpdated : SaveResult.RecordInserted);
                }
            }

            //SAVE IS SUCCESSFUL IF OBJECT IS NOT DIRTY
            return(SaveResult.NotDirty);
        }