예제 #1
0
        private static void SetPrimaryAddressId(int addressId, int userId)
        {
            string   updateQuery = "UPDATE ac_Users SET PrimaryAddressId = @addressId WHERE UserId = @userId";
            Database database    = Token.Instance.Database;

            using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery))
            {
                database.AddInParameter(updateCommand, "@addressId", DbType.Int32, NullableData.DbNullify(addressId));
                database.AddInParameter(updateCommand, "@userId", DbType.Int32, userId);
                database.ExecuteNonQuery(updateCommand);
            }
        }
        /// <summary>
        /// Saves this InputField 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;

                if (this.InputFieldId == 0)
                {
                    recordExists = false;
                }

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

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_InputFields SET ");
                    updateQuery.Append("ProductTemplateId = @ProductTemplateId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", UserPrompt = @UserPrompt");
                    updateQuery.Append(", InputTypeId = @InputTypeId");
                    updateQuery.Append(", Rows = @Rows");
                    updateQuery.Append(", Columns = @Columns");
                    updateQuery.Append(", MaxLength = @MaxLength");
                    updateQuery.Append(", IsRequired = @IsRequired");
                    updateQuery.Append(", RequiredMessage = @RequiredMessage");
                    updateQuery.Append(", IsMerchantField = @IsMerchantField");
                    updateQuery.Append(", PersistWithOrder = @PersistWithOrder");
                    updateQuery.Append(", PromptCssClass = @PromptCssClass");
                    updateQuery.Append(", ControlCssClass = @ControlCssClass");
                    updateQuery.Append(", AdditionalData = @AdditionalData");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE InputFieldId = @InputFieldId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@InputFieldId", System.Data.DbType.Int32, this.InputFieldId);
                        database.AddInParameter(updateCommand, "@ProductTemplateId", System.Data.DbType.Int32, this.ProductTemplateId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@UserPrompt", System.Data.DbType.String, this.UserPrompt);
                        database.AddInParameter(updateCommand, "@InputTypeId", System.Data.DbType.Int16, this.InputTypeId);
                        database.AddInParameter(updateCommand, "@Rows", System.Data.DbType.Byte, this.Rows);
                        database.AddInParameter(updateCommand, "@Columns", System.Data.DbType.Byte, this.Columns);
                        database.AddInParameter(updateCommand, "@MaxLength", System.Data.DbType.Int16, this.MaxLength);
                        database.AddInParameter(updateCommand, "@IsRequired", System.Data.DbType.Boolean, this.IsRequired);
                        database.AddInParameter(updateCommand, "@RequiredMessage", System.Data.DbType.String, NullableData.DbNullify(this.RequiredMessage));
                        database.AddInParameter(updateCommand, "@IsMerchantField", System.Data.DbType.Boolean, this.IsMerchantField);
                        database.AddInParameter(updateCommand, "@PersistWithOrder", System.Data.DbType.Boolean, this.PersistWithOrder);
                        database.AddInParameter(updateCommand, "@PromptCssClass", System.Data.DbType.String, NullableData.DbNullify(this.PromptCssClass));
                        database.AddInParameter(updateCommand, "@ControlCssClass", System.Data.DbType.String, NullableData.DbNullify(this.ControlCssClass));
                        database.AddInParameter(updateCommand, "@AdditionalData", System.Data.DbType.String, NullableData.DbNullify(this.AdditionalData));
                        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_InputFields (ProductTemplateId, Name, UserPrompt, InputTypeId, Rows, Columns, MaxLength, IsRequired, RequiredMessage, IsMerchantField, PersistWithOrder, PromptCssClass, ControlCssClass, AdditionalData, OrderBy)");
                    insertQuery.Append(" VALUES (@ProductTemplateId, @Name, @UserPrompt, @InputTypeId, @Rows, @Columns, @MaxLength, @IsRequired, @RequiredMessage, @IsMerchantField, @PersistWithOrder, @PromptCssClass, @ControlCssClass, @AdditionalData, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@InputFieldId", System.Data.DbType.Int32, this.InputFieldId);
                        database.AddInParameter(insertCommand, "@ProductTemplateId", System.Data.DbType.Int32, this.ProductTemplateId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@UserPrompt", System.Data.DbType.String, this.UserPrompt);
                        database.AddInParameter(insertCommand, "@InputTypeId", System.Data.DbType.Int16, this.InputTypeId);
                        database.AddInParameter(insertCommand, "@Rows", System.Data.DbType.Byte, this.Rows);
                        database.AddInParameter(insertCommand, "@Columns", System.Data.DbType.Byte, this.Columns);
                        database.AddInParameter(insertCommand, "@MaxLength", System.Data.DbType.Int16, this.MaxLength);
                        database.AddInParameter(insertCommand, "@IsRequired", System.Data.DbType.Boolean, this.IsRequired);
                        database.AddInParameter(insertCommand, "@RequiredMessage", System.Data.DbType.String, NullableData.DbNullify(this.RequiredMessage));
                        database.AddInParameter(insertCommand, "@IsMerchantField", System.Data.DbType.Boolean, this.IsMerchantField);
                        database.AddInParameter(insertCommand, "@PersistWithOrder", System.Data.DbType.Boolean, this.PersistWithOrder);
                        database.AddInParameter(insertCommand, "@PromptCssClass", System.Data.DbType.String, NullableData.DbNullify(this.PromptCssClass));
                        database.AddInParameter(insertCommand, "@ControlCssClass", System.Data.DbType.String, NullableData.DbNullify(this.ControlCssClass));
                        database.AddInParameter(insertCommand, "@AdditionalData", System.Data.DbType.String, NullableData.DbNullify(this.AdditionalData));
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result             = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._InputFieldId = 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);
        }
예제 #3
0
        /// <summary>
        /// Saves this OrderStatus 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.OrderStatusId == 0)
                {
                    recordExists = false;
                }

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

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_OrderStatuses SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", DisplayName = @DisplayName");
                    updateQuery.Append(", InventoryActionId = @InventoryActionId");
                    updateQuery.Append(", IsActive = @IsActive");
                    updateQuery.Append(", IsValid = @IsValid");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE OrderStatusId = @OrderStatusId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@OrderStatusId", System.Data.DbType.Int32, this.OrderStatusId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@DisplayName", System.Data.DbType.String, NullableData.DbNullify(this.DisplayName));
                        database.AddInParameter(updateCommand, "@InventoryActionId", System.Data.DbType.Int16, this.InventoryActionId);
                        database.AddInParameter(updateCommand, "@IsActive", System.Data.DbType.Boolean, this.IsActive);
                        database.AddInParameter(updateCommand, "@IsValid", System.Data.DbType.Boolean, this.IsValid);
                        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_OrderStatuses (StoreId, Name, DisplayName, InventoryActionId, IsActive, IsValid, OrderBy)");
                    insertQuery.Append(" VALUES (@StoreId, @Name, @DisplayName, @InventoryActionId, @IsActive, @IsValid, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@OrderStatusId", System.Data.DbType.Int32, this.OrderStatusId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@DisplayName", System.Data.DbType.String, NullableData.DbNullify(this.DisplayName));
                        database.AddInParameter(insertCommand, "@InventoryActionId", System.Data.DbType.Int16, this.InventoryActionId);
                        database.AddInParameter(insertCommand, "@IsActive", System.Data.DbType.Boolean, this.IsActive);
                        database.AddInParameter(insertCommand, "@IsValid", System.Data.DbType.Boolean, this.IsValid);
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._OrderStatusId = 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);
        }
예제 #4
0
        /// <summary>
        /// Saves this KitComponent 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.KitComponentId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_KitComponents SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", UserPrompt = @UserPrompt");
                    updateQuery.Append(", InputTypeId = @InputTypeId");
                    updateQuery.Append(", Columns = @Columns");
                    updateQuery.Append(", HeaderOption = @HeaderOption");
                    updateQuery.Append(" WHERE KitComponentId = @KitComponentId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@KitComponentId", System.Data.DbType.Int32, this.KitComponentId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@UserPrompt", System.Data.DbType.String, NullableData.DbNullify(this.UserPrompt));
                        database.AddInParameter(updateCommand, "@InputTypeId", System.Data.DbType.Int16, this.InputTypeId);
                        database.AddInParameter(updateCommand, "@Columns", System.Data.DbType.Byte, this.Columns);
                        database.AddInParameter(updateCommand, "@HeaderOption", System.Data.DbType.String, NullableData.DbNullify(this.HeaderOption));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_KitComponents (StoreId, Name, UserPrompt, InputTypeId, Columns, HeaderOption)");
                    insertQuery.Append(" VALUES (@StoreId, @Name, @UserPrompt, @InputTypeId, @Columns, @HeaderOption)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@KitComponentId", System.Data.DbType.Int32, this.KitComponentId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@UserPrompt", System.Data.DbType.String, NullableData.DbNullify(this.UserPrompt));
                        database.AddInParameter(insertCommand, "@InputTypeId", System.Data.DbType.Int16, this.InputTypeId);
                        database.AddInParameter(insertCommand, "@Columns", System.Data.DbType.Byte, this.Columns);
                        database.AddInParameter(insertCommand, "@HeaderOption", System.Data.DbType.String, NullableData.DbNullify(this.HeaderOption));
                        //RESULT IS NEW IDENTITY;
                        result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._KitComponentId = 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);
        }
 /// <summary>
 /// Changes the agreement for a group of digital goods.
 /// </summary>
 /// <param name="oldAgreementId">The agreement that digital goods are to be moved from.</param>
 /// <param name="newAgreementId">The agreement that digital goods are to be moved to.</param>
 public static void MoveDigitalGoods(int oldAgreementId, int newAgreementId)
 {
     if (oldAgreementId != newAgreementId)
     {
         int       storeId       = Token.Instance.StoreId;
         Database  database      = Token.Instance.Database;
         DbCommand selectCommand = database.GetSqlStringCommand("UPDATE ac_DigitalGoods SET LicenseAgreementId = @newAgreementId WHERE LicenseAgreementId = @oldAgreementId");
         database.AddInParameter(selectCommand, "@newAgreementId", System.Data.DbType.Int32, NullableData.DbNullify(newAgreementId));
         database.AddInParameter(selectCommand, "@oldAgreementId", System.Data.DbType.Int32, oldAgreementId);
         database.ExecuteNonQuery(selectCommand);
     }
 }
예제 #6
0
        /// <summary>
        /// Saves this ReviewerProfile object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        protected SaveResult BaseSave()
        {
            if (this.IsDirty)
            {
                Database database     = Token.Instance.Database;
                bool     recordExists = true;

                if (this.ReviewerProfileId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_ReviewerProfiles SET ");
                    updateQuery.Append("Email = @Email");
                    updateQuery.Append(", DisplayName = @DisplayName");
                    updateQuery.Append(", Location = @Location");
                    updateQuery.Append(", EmailVerified = @EmailVerified");
                    updateQuery.Append(", EmailVerificationCode = @EmailVerificationCode");
                    updateQuery.Append(" WHERE ReviewerProfileId = @ReviewerProfileId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@ReviewerProfileId", System.Data.DbType.Int32, this.ReviewerProfileId);
                        database.AddInParameter(updateCommand, "@Email", System.Data.DbType.String, this.Email);
                        database.AddInParameter(updateCommand, "@DisplayName", System.Data.DbType.String, this.DisplayName);
                        database.AddInParameter(updateCommand, "@Location", System.Data.DbType.String, NullableData.DbNullify(this.Location));
                        database.AddInParameter(updateCommand, "@EmailVerified", System.Data.DbType.Boolean, this.EmailVerified);
                        database.AddInParameter(updateCommand, "@EmailVerificationCode", System.Data.DbType.Guid, NullableData.DbNullify(this.EmailVerificationCode));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_ReviewerProfiles (Email, DisplayName, Location, EmailVerified, EmailVerificationCode)");
                    insertQuery.Append(" VALUES (@Email, @DisplayName, @Location, @EmailVerified, @EmailVerificationCode)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@ReviewerProfileId", System.Data.DbType.Int32, this.ReviewerProfileId);
                        database.AddInParameter(insertCommand, "@Email", System.Data.DbType.String, this.Email);
                        database.AddInParameter(insertCommand, "@DisplayName", System.Data.DbType.String, this.DisplayName);
                        database.AddInParameter(insertCommand, "@Location", System.Data.DbType.String, NullableData.DbNullify(this.Location));
                        database.AddInParameter(insertCommand, "@EmailVerified", System.Data.DbType.Boolean, this.EmailVerified);
                        database.AddInParameter(insertCommand, "@EmailVerificationCode", System.Data.DbType.Guid, NullableData.DbNullify(this.EmailVerificationCode));
                        //RESULT IS NEW IDENTITY;
                        result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._ReviewerProfileId = 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);
        }
예제 #7
0
        /// <summary>
        /// Saves this Basket object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        protected SaveResult BaseSave()
        {
            if (this.IsDirty)
            {
                Database database     = Token.Instance.Database;
                bool     recordExists = true;

                if (this.BasketId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Baskets SET ");
                    updateQuery.Append("UserId = @UserId");
                    updateQuery.Append(", ContentHash = @ContentHash");
                    updateQuery.Append(" WHERE BasketId = @BasketId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@BasketId", System.Data.DbType.Int32, this.BasketId);
                        database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(updateCommand, "@ContentHash", System.Data.DbType.String, NullableData.DbNullify(this.ContentHash));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Baskets (UserId, ContentHash)");
                    insertQuery.Append(" VALUES (@UserId, @ContentHash)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@BasketId", System.Data.DbType.Int32, this.BasketId);
                        database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(insertCommand, "@ContentHash", System.Data.DbType.String, NullableData.DbNullify(this.ContentHash));
                        //RESULT IS NEW IDENTITY;
                        result         = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._BasketId = 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);
        }
        /// <summary>
        /// Counts the number of DigitalGood objects for the given ReadmeId in the database.
        /// <param name="readmeId">The given ReadmeId</param>
        /// </summary>
        /// <returns>The Number of DigitalGood objects for the given ReadmeId in the database.</returns>
        public static int CountForReadme(Int32 readmeId)
        {
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand("SELECT COUNT(*) AS TotalRecords FROM ac_DigitalGoods WHERE ReadmeId = @readmeId");

            database.AddInParameter(selectCommand, "@readmeId", System.Data.DbType.Int32, NullableData.DbNullify(readmeId));
            return(CommerceBuilder.Utility.AlwaysConvert.ToInt(database.ExecuteScalar(selectCommand)));
        }
        /// <summary>
        /// Saves this UserPassword 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 DEFAULT FOR DATE FIELD
                if (this.CreateDate == System.DateTime.MinValue)
                {
                    this.CreateDate = LocaleHelper.LocalNow;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_UserPasswords SET ");
                    updateQuery.Append("Password = @Password");
                    updateQuery.Append(", PasswordFormat = @PasswordFormat");
                    updateQuery.Append(", CreateDate = @CreateDate");
                    updateQuery.Append(", ForceExpiration = @ForceExpiration");
                    updateQuery.Append(" WHERE UserId = @UserId AND PasswordNumber = @PasswordNumber");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(updateCommand, "@PasswordNumber", System.Data.DbType.Byte, this.PasswordNumber);
                        database.AddInParameter(updateCommand, "@Password", System.Data.DbType.String, this.Password);
                        database.AddInParameter(updateCommand, "@PasswordFormat", System.Data.DbType.String, NullableData.DbNullify(this.PasswordFormat));
                        database.AddInParameter(updateCommand, "@CreateDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreateDate));
                        database.AddInParameter(updateCommand, "@ForceExpiration", System.Data.DbType.Boolean, this.ForceExpiration);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_UserPasswords (UserId, PasswordNumber, Password, PasswordFormat, CreateDate, ForceExpiration)");
                    insertQuery.Append(" VALUES (@UserId, @PasswordNumber, @Password, @PasswordFormat, @CreateDate, @ForceExpiration)");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(insertCommand, "@PasswordNumber", System.Data.DbType.Byte, this.PasswordNumber);
                        database.AddInParameter(insertCommand, "@Password", System.Data.DbType.String, this.Password);
                        database.AddInParameter(insertCommand, "@PasswordFormat", System.Data.DbType.String, NullableData.DbNullify(this.PasswordFormat));
                        database.AddInParameter(insertCommand, "@CreateDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreateDate));
                        database.AddInParameter(insertCommand, "@ForceExpiration", System.Data.DbType.Boolean, this.ForceExpiration);
                        //RESULT IS NUMBER OF RECORDS AFFECTED;
                        result = database.ExecuteNonQuery(insertCommand);
                    }
                }

                //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);
        }
        /// <summary>
        /// Saves this KitProduct 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;

                if (this.KitProductId == 0)
                {
                    recordExists = false;
                }

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

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_KitProducts SET ");
                    updateQuery.Append("KitComponentId = @KitComponentId");
                    updateQuery.Append(", ProductId = @ProductId");
                    updateQuery.Append(", OptionList = @OptionList");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", Quantity = @Quantity");
                    updateQuery.Append(", Price = @Price");
                    updateQuery.Append(", PriceModeId = @PriceModeId");
                    updateQuery.Append(", Weight = @Weight");
                    updateQuery.Append(", WeightModeId = @WeightModeId");
                    updateQuery.Append(", IsSelected = @IsSelected");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE KitProductId = @KitProductId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@KitProductId", System.Data.DbType.Int32, this.KitProductId);
                        database.AddInParameter(updateCommand, "@KitComponentId", System.Data.DbType.Int32, this.KitComponentId);
                        database.AddInParameter(updateCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId);
                        database.AddInParameter(updateCommand, "@OptionList", System.Data.DbType.String, NullableData.DbNullify(this.OptionList));
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@Quantity", System.Data.DbType.Int16, this.Quantity);
                        database.AddInParameter(updateCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(updateCommand, "@PriceModeId", System.Data.DbType.Byte, this.PriceModeId);
                        database.AddInParameter(updateCommand, "@Weight", System.Data.DbType.Decimal, this.Weight);
                        database.AddInParameter(updateCommand, "@WeightModeId", System.Data.DbType.Byte, this.WeightModeId);
                        database.AddInParameter(updateCommand, "@IsSelected", System.Data.DbType.Boolean, this.IsSelected);
                        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_KitProducts (KitComponentId, ProductId, OptionList, Name, Quantity, Price, PriceModeId, Weight, WeightModeId, IsSelected, OrderBy)");
                    insertQuery.Append(" VALUES (@KitComponentId, @ProductId, @OptionList, @Name, @Quantity, @Price, @PriceModeId, @Weight, @WeightModeId, @IsSelected, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@KitProductId", System.Data.DbType.Int32, this.KitProductId);
                        database.AddInParameter(insertCommand, "@KitComponentId", System.Data.DbType.Int32, this.KitComponentId);
                        database.AddInParameter(insertCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId);
                        database.AddInParameter(insertCommand, "@OptionList", System.Data.DbType.String, NullableData.DbNullify(this.OptionList));
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@Quantity", System.Data.DbType.Int16, this.Quantity);
                        database.AddInParameter(insertCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(insertCommand, "@PriceModeId", System.Data.DbType.Byte, this.PriceModeId);
                        database.AddInParameter(insertCommand, "@Weight", System.Data.DbType.Decimal, this.Weight);
                        database.AddInParameter(insertCommand, "@WeightModeId", System.Data.DbType.Byte, this.WeightModeId);
                        database.AddInParameter(insertCommand, "@IsSelected", System.Data.DbType.Boolean, this.IsSelected);
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result             = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._KitProductId = result;
                    }
                }

                //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);
        }
예제 #11
0
        /// <summary>
        /// Saves this Option 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;

                if (this.OptionId == 0)
                {
                    recordExists = false;
                }

                //SET DEFAULT FOR DATE FIELD
                if (this.CreatedDate == System.DateTime.MinValue)
                {
                    this.CreatedDate = LocaleHelper.LocalNow;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Options SET ");
                    updateQuery.Append("Name = @Name");
                    updateQuery.Append(", HeaderText = @HeaderText");
                    updateQuery.Append(", ShowThumbnails = @ShowThumbnails");
                    updateQuery.Append(", ThumbnailColumns = @ThumbnailColumns");
                    updateQuery.Append(", ThumbnailWidth = @ThumbnailWidth");
                    updateQuery.Append(", ThumbnailHeight = @ThumbnailHeight");
                    updateQuery.Append(", CreatedDate = @CreatedDate");
                    updateQuery.Append(" WHERE OptionId = @OptionId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@OptionId", System.Data.DbType.Int32, this.OptionId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@HeaderText", System.Data.DbType.String, NullableData.DbNullify(this.HeaderText));
                        database.AddInParameter(updateCommand, "@ShowThumbnails", System.Data.DbType.Boolean, this.ShowThumbnails);
                        database.AddInParameter(updateCommand, "@ThumbnailColumns", System.Data.DbType.Byte, this.ThumbnailColumns);
                        database.AddInParameter(updateCommand, "@ThumbnailWidth", System.Data.DbType.Int16, this.ThumbnailWidth);
                        database.AddInParameter(updateCommand, "@ThumbnailHeight", System.Data.DbType.Int16, this.ThumbnailHeight);
                        database.AddInParameter(updateCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Options (Name, HeaderText, ShowThumbnails, ThumbnailColumns, ThumbnailWidth, ThumbnailHeight, CreatedDate)");
                    insertQuery.Append(" VALUES (@Name, @HeaderText, @ShowThumbnails, @ThumbnailColumns, @ThumbnailWidth, @ThumbnailHeight, @CreatedDate)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@OptionId", System.Data.DbType.Int32, this.OptionId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@HeaderText", System.Data.DbType.String, NullableData.DbNullify(this.HeaderText));
                        database.AddInParameter(insertCommand, "@ShowThumbnails", System.Data.DbType.Boolean, this.ShowThumbnails);
                        database.AddInParameter(insertCommand, "@ThumbnailColumns", System.Data.DbType.Byte, this.ThumbnailColumns);
                        database.AddInParameter(insertCommand, "@ThumbnailWidth", System.Data.DbType.Int16, this.ThumbnailWidth);
                        database.AddInParameter(insertCommand, "@ThumbnailHeight", System.Data.DbType.Int16, this.ThumbnailHeight);
                        database.AddInParameter(insertCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate));
                        //RESULT IS NEW IDENTITY;
                        result         = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._OptionId = 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);
        }
예제 #12
0
        /// <summary>
        /// Saves this Profile object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        protected SaveResult BaseSave()
        {
            if (this.IsDirty)
            {
                Database database     = Token.Instance.Database;
                bool     recordExists = true;

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Profiles SET ");
                    updateQuery.Append("PropertyNames = @PropertyNames");
                    updateQuery.Append(", PropertyValuesString = @PropertyValuesString");
                    updateQuery.Append(", PropertyValuesBinary = @PropertyValuesBinary");
                    updateQuery.Append(", LastUpdatedDate = @LastUpdatedDate");
                    updateQuery.Append(" WHERE UserId = @UserId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(updateCommand, "@PropertyNames", System.Data.DbType.String, this.PropertyNames);
                        database.AddInParameter(updateCommand, "@PropertyValuesString", System.Data.DbType.String, this.PropertyValuesString);
                        database.AddInParameter(updateCommand, "@PropertyValuesBinary", System.Data.DbType.Binary, this.PropertyValuesBinary);
                        database.AddInParameter(updateCommand, "@LastUpdatedDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastUpdatedDate)));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Profiles (UserId, PropertyNames, PropertyValuesString, PropertyValuesBinary, LastUpdatedDate)");
                    insertQuery.Append(" VALUES (@UserId, @PropertyNames, @PropertyValuesString, @PropertyValuesBinary, @LastUpdatedDate)");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(insertCommand, "@PropertyNames", System.Data.DbType.String, this.PropertyNames);
                        database.AddInParameter(insertCommand, "@PropertyValuesString", System.Data.DbType.String, this.PropertyValuesString);
                        database.AddInParameter(insertCommand, "@PropertyValuesBinary", System.Data.DbType.Binary, this.PropertyValuesBinary);
                        database.AddInParameter(insertCommand, "@LastUpdatedDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastUpdatedDate)));
                        //RESULT IS NUMBER OF RECORDS AFFECTED;
                        result = database.ExecuteNonQuery(insertCommand);
                    }
                }

                //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);
        }
예제 #13
0
        /// <summary>
        /// Saves this TaxRule 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.TaxRuleId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_TaxRules SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", TaxRate = @TaxRate");
                    updateQuery.Append(", UseBillingAddress = @UseBillingAddress");
                    updateQuery.Append(", GroupRuleId = @GroupRuleId");
                    updateQuery.Append(", TaxCodeId = @TaxCodeId");
                    updateQuery.Append(", Priority = @Priority");
                    updateQuery.Append(", RoundingRuleId = @RoundingRuleId");
                    updateQuery.Append(", UsePerItemTax = @UsePerItemTax");
                    updateQuery.Append(" WHERE TaxRuleId = @TaxRuleId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@TaxRuleId", System.Data.DbType.Int32, this.TaxRuleId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@TaxRate", System.Data.DbType.Decimal, this.TaxRate);
                        database.AddInParameter(updateCommand, "@UseBillingAddress", System.Data.DbType.Boolean, this.UseBillingAddress);
                        database.AddInParameter(updateCommand, "@GroupRuleId", System.Data.DbType.Byte, this.GroupRuleId);
                        database.AddInParameter(updateCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(updateCommand, "@Priority", System.Data.DbType.Int16, this.Priority);
                        database.AddInParameter(updateCommand, "@RoundingRuleId", System.Data.DbType.Byte, this.RoundingRuleId);
                        database.AddInParameter(updateCommand, "@UsePerItemTax", System.Data.DbType.Boolean, this.UsePerItemTax);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_TaxRules (StoreId, Name, TaxRate, UseBillingAddress, GroupRuleId, TaxCodeId, Priority, RoundingRuleId, UsePerItemTax)");
                    insertQuery.Append(" VALUES (@StoreId, @Name, @TaxRate, @UseBillingAddress, @GroupRuleId, @TaxCodeId, @Priority, @RoundingRuleId, @UsePerItemTax)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@TaxRuleId", System.Data.DbType.Int32, this.TaxRuleId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@TaxRate", System.Data.DbType.Decimal, this.TaxRate);
                        database.AddInParameter(insertCommand, "@UseBillingAddress", System.Data.DbType.Boolean, this.UseBillingAddress);
                        database.AddInParameter(insertCommand, "@GroupRuleId", System.Data.DbType.Byte, this.GroupRuleId);
                        database.AddInParameter(insertCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(insertCommand, "@Priority", System.Data.DbType.Int16, this.Priority);
                        database.AddInParameter(insertCommand, "@RoundingRuleId", System.Data.DbType.Byte, this.RoundingRuleId);
                        database.AddInParameter(insertCommand, "@UsePerItemTax", System.Data.DbType.Boolean, this.UsePerItemTax);
                        //RESULT IS NEW IDENTITY;
                        result          = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._TaxRuleId = 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);
        }
예제 #14
0
        /// <summary>
        /// Saves this Special 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;

                if (this.SpecialId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Specials SET ");
                    updateQuery.Append("ProductId = @ProductId");
                    updateQuery.Append(", Price = @Price");
                    updateQuery.Append(", StartDate = @StartDate");
                    updateQuery.Append(", EndDate = @EndDate");
                    updateQuery.Append(" WHERE SpecialId = @SpecialId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@SpecialId", System.Data.DbType.Int32, this.SpecialId);
                        database.AddInParameter(updateCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId);
                        database.AddInParameter(updateCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(updateCommand, "@StartDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.StartDate)));
                        database.AddInParameter(updateCommand, "@EndDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.EndDate)));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Specials (ProductId, Price, StartDate, EndDate)");
                    insertQuery.Append(" VALUES (@ProductId, @Price, @StartDate, @EndDate)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@SpecialId", System.Data.DbType.Int32, this.SpecialId);
                        database.AddInParameter(insertCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId);
                        database.AddInParameter(insertCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(insertCommand, "@StartDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.StartDate)));
                        database.AddInParameter(insertCommand, "@EndDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.EndDate)));
                        //RESULT IS NEW IDENTITY;
                        result          = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._SpecialId = 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);
        }
예제 #15
0
        /// <summary>
        /// Saves this ShipMethod 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.ShipMethodId == 0)
                {
                    recordExists = false;
                }

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

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_ShipMethods SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", ShipMethodTypeId = @ShipMethodTypeId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", Surcharge = @Surcharge");
                    updateQuery.Append(", ShipGatewayId = @ShipGatewayId");
                    updateQuery.Append(", ServiceCode = @ServiceCode");
                    updateQuery.Append(", MinPurchase = @MinPurchase");
                    updateQuery.Append(", SurchargeIsVisible = @SurchargeIsVisible");
                    updateQuery.Append(", SurchargeIsPercent = @SurchargeIsPercent");
                    updateQuery.Append(", TaxCodeId = @TaxCodeId");
                    updateQuery.Append(", SurchargeTaxCodeId = @SurchargeTaxCodeId");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE ShipMethodId = @ShipMethodId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@ShipMethodId", System.Data.DbType.Int32, this.ShipMethodId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@ShipMethodTypeId", System.Data.DbType.Int16, this.ShipMethodTypeId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@Surcharge", System.Data.DbType.Decimal, this.Surcharge);
                        database.AddInParameter(updateCommand, "@ShipGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.ShipGatewayId));
                        database.AddInParameter(updateCommand, "@ServiceCode", System.Data.DbType.String, NullableData.DbNullify(this.ServiceCode));
                        database.AddInParameter(updateCommand, "@MinPurchase", System.Data.DbType.Decimal, this.MinPurchase);
                        database.AddInParameter(updateCommand, "@SurchargeIsVisible", System.Data.DbType.Boolean, this.SurchargeIsVisible);
                        database.AddInParameter(updateCommand, "@SurchargeIsPercent", System.Data.DbType.Boolean, NullableData.DbNullify(this.SurchargeIsPercent));
                        database.AddInParameter(updateCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(updateCommand, "@SurchargeTaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.SurchargeTaxCodeId));
                        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_ShipMethods (StoreId, ShipMethodTypeId, Name, Surcharge, ShipGatewayId, ServiceCode, MinPurchase, SurchargeIsVisible, SurchargeIsPercent, TaxCodeId, SurchargeTaxCodeId, OrderBy)");
                    insertQuery.Append(" VALUES (@StoreId, @ShipMethodTypeId, @Name, @Surcharge, @ShipGatewayId, @ServiceCode, @MinPurchase, @SurchargeIsVisible, @SurchargeIsPercent, @TaxCodeId, @SurchargeTaxCodeId, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@ShipMethodId", System.Data.DbType.Int32, this.ShipMethodId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@ShipMethodTypeId", System.Data.DbType.Int16, this.ShipMethodTypeId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@Surcharge", System.Data.DbType.Decimal, this.Surcharge);
                        database.AddInParameter(insertCommand, "@ShipGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.ShipGatewayId));
                        database.AddInParameter(insertCommand, "@ServiceCode", System.Data.DbType.String, NullableData.DbNullify(this.ServiceCode));
                        database.AddInParameter(insertCommand, "@MinPurchase", System.Data.DbType.Decimal, this.MinPurchase);
                        database.AddInParameter(insertCommand, "@SurchargeIsVisible", System.Data.DbType.Boolean, this.SurchargeIsVisible);
                        database.AddInParameter(insertCommand, "@SurchargeIsPercent", System.Data.DbType.Boolean, NullableData.DbNullify(this.SurchargeIsPercent));
                        database.AddInParameter(insertCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(insertCommand, "@SurchargeTaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.SurchargeTaxCodeId));
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result             = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._ShipMethodId = 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);
        }
예제 #16
0
        /// <summary>
        /// Saves this OrderNote object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        protected SaveResult BaseSave()
        {
            if (this.IsDirty)
            {
                Database database     = Token.Instance.Database;
                bool     recordExists = true;

                if (this.OrderNoteId == 0)
                {
                    recordExists = false;
                }

                //SET DEFAULT FOR DATE FIELD
                if (this.CreatedDate == System.DateTime.MinValue)
                {
                    this.CreatedDate = LocaleHelper.LocalNow;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_OrderNotes SET ");
                    updateQuery.Append("OrderId = @OrderId");
                    updateQuery.Append(", UserId = @UserId");
                    updateQuery.Append(", CreatedDate = @CreatedDate");
                    updateQuery.Append(", Comment = @Comment");
                    updateQuery.Append(", NoteTypeId = @NoteTypeId");
                    updateQuery.Append(" WHERE OrderNoteId = @OrderNoteId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@OrderNoteId", System.Data.DbType.Int32, this.OrderNoteId);
                        database.AddInParameter(updateCommand, "@OrderId", System.Data.DbType.Int32, this.OrderId);
                        database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, NullableData.DbNullify(this.UserId));
                        database.AddInParameter(updateCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate));
                        database.AddInParameter(updateCommand, "@Comment", System.Data.DbType.String, this.Comment);
                        database.AddInParameter(updateCommand, "@NoteTypeId", System.Data.DbType.Byte, this.NoteTypeId);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_OrderNotes (OrderId, UserId, CreatedDate, Comment, NoteTypeId)");
                    insertQuery.Append(" VALUES (@OrderId, @UserId, @CreatedDate, @Comment, @NoteTypeId)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@OrderNoteId", System.Data.DbType.Int32, this.OrderNoteId);
                        database.AddInParameter(insertCommand, "@OrderId", System.Data.DbType.Int32, this.OrderId);
                        database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, NullableData.DbNullify(this.UserId));
                        database.AddInParameter(insertCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate));
                        database.AddInParameter(insertCommand, "@Comment", System.Data.DbType.String, this.Comment);
                        database.AddInParameter(insertCommand, "@NoteTypeId", System.Data.DbType.Byte, this.NoteTypeId);
                        //RESULT IS NEW IDENTITY;
                        result            = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._OrderNoteId = result;
                    }
                }

                //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);
        }
예제 #17
0
        /// <summary>
        /// Saves this BannedIP 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.BannedIPId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_BannedIPs SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", IPRangeStart = @IPRangeStart");
                    updateQuery.Append(", IPRangeEnd = @IPRangeEnd");
                    updateQuery.Append(", Comment = @Comment");
                    updateQuery.Append(" WHERE BannedIPId = @BannedIPId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@BannedIPId", System.Data.DbType.Int32, this.BannedIPId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@IPRangeStart", System.Data.DbType.Int64, this.IPRangeStart);
                        database.AddInParameter(updateCommand, "@IPRangeEnd", System.Data.DbType.Int64, this.IPRangeEnd);
                        database.AddInParameter(updateCommand, "@Comment", System.Data.DbType.String, NullableData.DbNullify(this.Comment));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_BannedIPs (StoreId, IPRangeStart, IPRangeEnd, Comment)");
                    insertQuery.Append(" VALUES (@StoreId, @IPRangeStart, @IPRangeEnd, @Comment)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@BannedIPId", System.Data.DbType.Int32, this.BannedIPId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@IPRangeStart", System.Data.DbType.Int64, this.IPRangeStart);
                        database.AddInParameter(insertCommand, "@IPRangeEnd", System.Data.DbType.Int64, this.IPRangeEnd);
                        database.AddInParameter(insertCommand, "@Comment", System.Data.DbType.String, NullableData.DbNullify(this.Comment));
                        //RESULT IS NEW IDENTITY;
                        result           = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._BannedIPId = result;
                    }
                }

                //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);
        }
예제 #18
0
        /// <summary>
        /// Saves this Webpage object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        protected SaveResult BaseSave()
        {
            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.WebpageId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Webpages SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", Summary = @Summary");
                    updateQuery.Append(", Description = @Description");
                    updateQuery.Append(", ThumbnailUrl = @ThumbnailUrl");
                    updateQuery.Append(", ThumbnailAltText = @ThumbnailAltText");
                    updateQuery.Append(", DisplayPage = @DisplayPage");
                    updateQuery.Append(", Theme = @Theme");
                    updateQuery.Append(", HtmlHead = @HtmlHead");
                    updateQuery.Append(", VisibilityId = @VisibilityId");
                    updateQuery.Append(" WHERE WebpageId = @WebpageId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@WebpageId", System.Data.DbType.Int32, this.WebpageId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, NullableData.DbNullify(this.Name));
                        database.AddInParameter(updateCommand, "@Summary", System.Data.DbType.String, NullableData.DbNullify(this.Summary));
                        database.AddInParameter(updateCommand, "@Description", System.Data.DbType.String, NullableData.DbNullify(this.Description));
                        database.AddInParameter(updateCommand, "@ThumbnailUrl", System.Data.DbType.String, NullableData.DbNullify(this.ThumbnailUrl));
                        database.AddInParameter(updateCommand, "@ThumbnailAltText", System.Data.DbType.String, NullableData.DbNullify(_ThumbnailAltText));
                        database.AddInParameter(updateCommand, "@DisplayPage", System.Data.DbType.String, NullableData.DbNullify(this.DisplayPage));
                        database.AddInParameter(updateCommand, "@Theme", System.Data.DbType.String, NullableData.DbNullify(this.Theme));
                        database.AddInParameter(updateCommand, "@HtmlHead", System.Data.DbType.String, NullableData.DbNullify(this.HtmlHead));
                        database.AddInParameter(updateCommand, "@VisibilityId", System.Data.DbType.Byte, this.VisibilityId);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Webpages (StoreId, Name, Summary, Description, ThumbnailUrl, ThumbnailAltText, DisplayPage, Theme, HtmlHead, VisibilityId)");
                    insertQuery.Append(" VALUES (@StoreId, @Name, @Summary, @Description, @ThumbnailUrl, @ThumbnailAltText, @DisplayPage, @Theme, @HtmlHead, @VisibilityId)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@WebpageId", System.Data.DbType.Int32, this.WebpageId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, NullableData.DbNullify(this.Name));
                        database.AddInParameter(insertCommand, "@Summary", System.Data.DbType.String, NullableData.DbNullify(this.Summary));
                        database.AddInParameter(insertCommand, "@Description", System.Data.DbType.String, NullableData.DbNullify(this.Description));
                        database.AddInParameter(insertCommand, "@ThumbnailUrl", System.Data.DbType.String, NullableData.DbNullify(this.ThumbnailUrl));
                        database.AddInParameter(insertCommand, "@ThumbnailAltText", System.Data.DbType.String, NullableData.DbNullify(_ThumbnailAltText));
                        database.AddInParameter(insertCommand, "@DisplayPage", System.Data.DbType.String, NullableData.DbNullify(this.DisplayPage));
                        database.AddInParameter(insertCommand, "@Theme", System.Data.DbType.String, NullableData.DbNullify(this.Theme));
                        database.AddInParameter(insertCommand, "@HtmlHead", System.Data.DbType.String, NullableData.DbNullify(this.HtmlHead));
                        database.AddInParameter(insertCommand, "@VisibilityId", System.Data.DbType.Byte, this.VisibilityId);
                        //RESULT IS NEW IDENTITY;
                        result          = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._WebpageId = result;
                    }
                }

                //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);
        }
        public static DigitalGoodCollection LoadForReadme(Int32 readmeId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //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(" " + DigitalGood.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_DigitalGoods");
            selectQuery.Append(" WHERE ReadmeId = @readmeId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@readmeId", System.Data.DbType.Int32, NullableData.DbNullify(readmeId));
            //EXECUTE THE COMMAND
            DigitalGoodCollection results = new DigitalGoodCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        DigitalGood digitalGood = new DigitalGood();
                        DigitalGood.LoadDataReader(digitalGood, dr);
                        results.Add(digitalGood);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
예제 #20
0
        /// <summary>
        /// Saves this OrderItem 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;

                if (this.OrderItemId == 0)
                {
                    recordExists = false;
                }

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

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_OrderItems SET ");
                    updateQuery.Append("OrderId = @OrderId");
                    updateQuery.Append(", ParentItemId = @ParentItemId");
                    updateQuery.Append(", OrderItemTypeId = @OrderItemTypeId");
                    updateQuery.Append(", ShippableId = @ShippableId");
                    updateQuery.Append(", OrderShipmentId = @OrderShipmentId");
                    updateQuery.Append(", ProductId = @ProductId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", OptionList = @OptionList");
                    updateQuery.Append(", VariantName = @VariantName");
                    updateQuery.Append(", Sku = @Sku");
                    updateQuery.Append(", Price = @Price");
                    updateQuery.Append(", Weight = @Weight");
                    updateQuery.Append(", CostOfGoods = @CostOfGoods");
                    updateQuery.Append(", Quantity = @Quantity");
                    updateQuery.Append(", LineMessage = @LineMessage");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(", GiftMessage = @GiftMessage");
                    updateQuery.Append(", TaxCodeId = @TaxCodeId");
                    updateQuery.Append(", WrapStyleId = @WrapStyleId");
                    updateQuery.Append(", WishlistItemId = @WishlistItemId");
                    updateQuery.Append(", InventoryStatusId = @InventoryStatusId");
                    updateQuery.Append(", TaxRate = @TaxRate");
                    updateQuery.Append(", TaxAmount = @TaxAmount");
                    updateQuery.Append(", KitList = @KitList");
                    updateQuery.Append(", CustomFields = @CustomFields");
                    updateQuery.Append(" WHERE OrderItemId = @OrderItemId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@OrderItemId", System.Data.DbType.Int32, this.OrderItemId);
                        database.AddInParameter(updateCommand, "@OrderId", System.Data.DbType.Int32, this.OrderId);
                        database.AddInParameter(updateCommand, "@ParentItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.ParentItemId));
                        database.AddInParameter(updateCommand, "@OrderItemTypeId", System.Data.DbType.Int16, this.OrderItemTypeId);
                        database.AddInParameter(updateCommand, "@ShippableId", System.Data.DbType.Byte, this.ShippableId);
                        database.AddInParameter(updateCommand, "@OrderShipmentId", System.Data.DbType.Int32, NullableData.DbNullify(this.OrderShipmentId));
                        database.AddInParameter(updateCommand, "@ProductId", System.Data.DbType.Int32, NullableData.DbNullify(this.ProductId));
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@OptionList", System.Data.DbType.String, NullableData.DbNullify(this.OptionList));
                        database.AddInParameter(updateCommand, "@VariantName", System.Data.DbType.String, NullableData.DbNullify(this.VariantName));
                        database.AddInParameter(updateCommand, "@Sku", System.Data.DbType.String, NullableData.DbNullify(this.Sku));
                        database.AddInParameter(updateCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(updateCommand, "@Weight", System.Data.DbType.Decimal, this.Weight);
                        database.AddInParameter(updateCommand, "@CostOfGoods", System.Data.DbType.Decimal, this.CostOfGoods);
                        database.AddInParameter(updateCommand, "@Quantity", System.Data.DbType.Int16, this.Quantity);
                        database.AddInParameter(updateCommand, "@LineMessage", System.Data.DbType.String, NullableData.DbNullify(this.LineMessage));
                        database.AddInParameter(updateCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        database.AddInParameter(updateCommand, "@GiftMessage", System.Data.DbType.String, NullableData.DbNullify(this.GiftMessage));
                        database.AddInParameter(updateCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(updateCommand, "@WrapStyleId", System.Data.DbType.Int32, NullableData.DbNullify(this.WrapStyleId));
                        database.AddInParameter(updateCommand, "@WishlistItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.WishlistItemId));
                        database.AddInParameter(updateCommand, "@InventoryStatusId", System.Data.DbType.Int16, this.InventoryStatusId);
                        database.AddInParameter(updateCommand, "@TaxRate", System.Data.DbType.Decimal, this.TaxRate);
                        database.AddInParameter(updateCommand, "@TaxAmount", System.Data.DbType.Decimal, this.TaxAmount);
                        database.AddInParameter(updateCommand, "@KitList", System.Data.DbType.String, NullableData.DbNullify(this.KitList));
                        database.AddInParameter(updateCommand, "@CustomFields", System.Data.DbType.String, NullableData.DbNullify(this.CustomFields.ToString()));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_OrderItems (OrderId, ParentItemId, OrderItemTypeId, ShippableId, OrderShipmentId, ProductId, Name, OptionList, VariantName, Sku, Price, Weight, CostOfGoods, Quantity, LineMessage, OrderBy, GiftMessage, TaxCodeId, WrapStyleId, WishlistItemId, InventoryStatusId, TaxRate, TaxAmount, KitList, CustomFields)");
                    insertQuery.Append(" VALUES (@OrderId, @ParentItemId, @OrderItemTypeId, @ShippableId, @OrderShipmentId, @ProductId, @Name, @OptionList, @VariantName, @Sku, @Price, @Weight, @CostOfGoods, @Quantity, @LineMessage, @OrderBy, @GiftMessage, @TaxCodeId, @WrapStyleId, @WishlistItemId, @InventoryStatusId, @TaxRate, @TaxAmount, @KitList, @CustomFields)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@OrderItemId", System.Data.DbType.Int32, this.OrderItemId);
                        database.AddInParameter(insertCommand, "@OrderId", System.Data.DbType.Int32, this.OrderId);
                        database.AddInParameter(insertCommand, "@ParentItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.ParentItemId));
                        database.AddInParameter(insertCommand, "@OrderItemTypeId", System.Data.DbType.Int16, this.OrderItemTypeId);
                        database.AddInParameter(insertCommand, "@ShippableId", System.Data.DbType.Byte, this.ShippableId);
                        database.AddInParameter(insertCommand, "@OrderShipmentId", System.Data.DbType.Int32, NullableData.DbNullify(this.OrderShipmentId));
                        database.AddInParameter(insertCommand, "@ProductId", System.Data.DbType.Int32, NullableData.DbNullify(this.ProductId));
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@OptionList", System.Data.DbType.String, NullableData.DbNullify(this.OptionList));
                        database.AddInParameter(insertCommand, "@VariantName", System.Data.DbType.String, NullableData.DbNullify(this.VariantName));
                        database.AddInParameter(insertCommand, "@Sku", System.Data.DbType.String, NullableData.DbNullify(this.Sku));
                        database.AddInParameter(insertCommand, "@Price", System.Data.DbType.Decimal, this.Price);
                        database.AddInParameter(insertCommand, "@Weight", System.Data.DbType.Decimal, this.Weight);
                        database.AddInParameter(insertCommand, "@CostOfGoods", System.Data.DbType.Decimal, this.CostOfGoods);
                        database.AddInParameter(insertCommand, "@Quantity", System.Data.DbType.Int16, this.Quantity);
                        database.AddInParameter(insertCommand, "@LineMessage", System.Data.DbType.String, NullableData.DbNullify(this.LineMessage));
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        database.AddInParameter(insertCommand, "@GiftMessage", System.Data.DbType.String, NullableData.DbNullify(this.GiftMessage));
                        database.AddInParameter(insertCommand, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId));
                        database.AddInParameter(insertCommand, "@WrapStyleId", System.Data.DbType.Int32, NullableData.DbNullify(this.WrapStyleId));
                        database.AddInParameter(insertCommand, "@WishlistItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.WishlistItemId));
                        database.AddInParameter(insertCommand, "@InventoryStatusId", System.Data.DbType.Int16, this.InventoryStatusId);
                        database.AddInParameter(insertCommand, "@TaxRate", System.Data.DbType.Decimal, this.TaxRate);
                        database.AddInParameter(insertCommand, "@TaxAmount", System.Data.DbType.Decimal, this.TaxAmount);
                        database.AddInParameter(insertCommand, "@KitList", System.Data.DbType.String, NullableData.DbNullify(this.KitList));
                        database.AddInParameter(insertCommand, "@CustomFields", System.Data.DbType.String, NullableData.DbNullify(this.CustomFields.ToString()));
                        //RESULT IS NEW IDENTITY;
                        result            = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._OrderItemId = 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);
        }
예제 #21
0
        /// <summary>
        /// Saves this Country 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 (recordExists)
                {
                    //verify whether record is already present
                    StringBuilder selectQuery = new StringBuilder();
                    selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_Countries");
                    selectQuery.Append(" WHERE CountryCode = @CountryCode");
                    using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()))
                    {
                        database.AddInParameter(selectCommand, "@CountryCode", System.Data.DbType.String, this.CountryCode);
                        if ((int)database.ExecuteScalar(selectCommand) == 0)
                        {
                            recordExists = false;
                        }
                    }
                }

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Countries SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", AddressFormat = @AddressFormat");
                    updateQuery.Append(" WHERE CountryCode = @CountryCode");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@CountryCode", System.Data.DbType.String, this.CountryCode);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@AddressFormat", System.Data.DbType.String, NullableData.DbNullify(this.AddressFormat));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Countries (CountryCode, StoreId, Name, AddressFormat)");
                    insertQuery.Append(" VALUES (@CountryCode, @StoreId, @Name, @AddressFormat)");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@CountryCode", System.Data.DbType.String, this.CountryCode);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@AddressFormat", System.Data.DbType.String, NullableData.DbNullify(this.AddressFormat));
                        //RESULT IS NUMBER OF RECORDS AFFECTED;
                        result = database.ExecuteNonQuery(insertCommand);
                    }
                }
                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);
        }
예제 #22
0
        /// <summary>
        /// Counts the number of Transaction objects for the given PaymentGatewayId in the database.
        /// <param name="paymentGatewayId">The given PaymentGatewayId</param>
        /// </summary>
        /// <returns>The Number of Transaction objects for the given PaymentGatewayId in the database.</returns>
        public static int CountForPaymentGateway(Int32 paymentGatewayId)
        {
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand("SELECT COUNT(*) AS TotalRecords FROM ac_Transactions WHERE PaymentGatewayId = @paymentGatewayId");

            database.AddInParameter(selectCommand, "@paymentGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(paymentGatewayId));
            return(CommerceBuilder.Utility.AlwaysConvert.ToInt(database.ExecuteScalar(selectCommand)));
        }
        /// <summary>
        /// Saves this CategoryParent 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;

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_CategoryParents SET ");
                    updateQuery.Append("ParentLevel = @ParentLevel");
                    updateQuery.Append(", ParentNumber = @ParentNumber");
                    updateQuery.Append(" WHERE CategoryId = @CategoryId AND ParentId = @ParentId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@CategoryId", System.Data.DbType.Int32, this.CategoryId);
                        database.AddInParameter(updateCommand, "@ParentId", System.Data.DbType.Int32, this.ParentId);
                        database.AddInParameter(updateCommand, "@ParentLevel", System.Data.DbType.Byte, NullableData.DbNullify(this.ParentLevel));
                        database.AddInParameter(updateCommand, "@ParentNumber", System.Data.DbType.Byte, NullableData.DbNullify(this.ParentNumber));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_CategoryParents (CategoryId, ParentId, ParentLevel, ParentNumber)");
                    insertQuery.Append(" VALUES (@CategoryId, @ParentId, @ParentLevel, @ParentNumber)");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@CategoryId", System.Data.DbType.Int32, this.CategoryId);
                        database.AddInParameter(insertCommand, "@ParentId", System.Data.DbType.Int32, this.ParentId);
                        database.AddInParameter(insertCommand, "@ParentLevel", System.Data.DbType.Byte, NullableData.DbNullify(this.ParentLevel));
                        database.AddInParameter(insertCommand, "@ParentNumber", System.Data.DbType.Byte, NullableData.DbNullify(this.ParentNumber));
                        //RESULT IS NUMBER OF RECORDS AFFECTED;
                        result = database.ExecuteNonQuery(insertCommand);
                    }
                }

                //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);
        }
        public static PaymentMethodCollection LoadForPaymentGateway(Int32 paymentGatewayId, 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");
            selectQuery.Append(" WHERE PaymentGatewayId = @paymentGatewayId");
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@paymentGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(paymentGatewayId));
            //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);
        }
예제 #25
0
        /// <summary>
        /// Saves this Currency object to the database.
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        protected SaveResult BaseSave()
        {
            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.CurrencyId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Currencies SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", CurrencySymbol = @CurrencySymbol");
                    updateQuery.Append(", DecimalDigits = @DecimalDigits");
                    updateQuery.Append(", DecimalSeparator = @DecimalSeparator");
                    updateQuery.Append(", GroupSeparator = @GroupSeparator");
                    updateQuery.Append(", GroupSizes = @GroupSizes");
                    updateQuery.Append(", NegativePattern = @NegativePattern");
                    updateQuery.Append(", NegativeSign = @NegativeSign");
                    updateQuery.Append(", PositivePattern = @PositivePattern");
                    updateQuery.Append(", ISOCode = @ISOCode");
                    updateQuery.Append(", ISOCodePattern = @ISOCodePattern");
                    updateQuery.Append(", ExchangeRate = @ExchangeRate");
                    updateQuery.Append(", AutoUpdate = @AutoUpdate");
                    updateQuery.Append(", LastUpdate = @LastUpdate");
                    updateQuery.Append(" WHERE CurrencyId = @CurrencyId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@CurrencyId", System.Data.DbType.Int32, this.CurrencyId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@CurrencySymbol", System.Data.DbType.String, NullableData.DbNullify(this.CurrencySymbol));
                        database.AddInParameter(updateCommand, "@DecimalDigits", System.Data.DbType.Int32, this.DecimalDigits);
                        database.AddInParameter(updateCommand, "@DecimalSeparator", System.Data.DbType.String, NullableData.DbNullify(this.DecimalSeparator));
                        database.AddInParameter(updateCommand, "@GroupSeparator", System.Data.DbType.String, NullableData.DbNullify(this.GroupSeparator));
                        database.AddInParameter(updateCommand, "@GroupSizes", System.Data.DbType.String, NullableData.DbNullify(this.GroupSizes));
                        database.AddInParameter(updateCommand, "@NegativePattern", System.Data.DbType.Byte, this.NegativePattern);
                        database.AddInParameter(updateCommand, "@NegativeSign", System.Data.DbType.String, NullableData.DbNullify(this.NegativeSign));
                        database.AddInParameter(updateCommand, "@PositivePattern", System.Data.DbType.Byte, this.PositivePattern);
                        database.AddInParameter(updateCommand, "@ISOCode", System.Data.DbType.String, this.ISOCode);
                        database.AddInParameter(updateCommand, "@ISOCodePattern", System.Data.DbType.Byte, NullableData.DbNullify(this.ISOCodePattern));
                        database.AddInParameter(updateCommand, "@ExchangeRate", System.Data.DbType.Decimal, this.ExchangeRate);
                        database.AddInParameter(updateCommand, "@AutoUpdate", System.Data.DbType.Boolean, this.AutoUpdate);
                        database.AddInParameter(updateCommand, "@LastUpdate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastUpdate)));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Currencies (StoreId, Name, CurrencySymbol, DecimalDigits, DecimalSeparator, GroupSeparator, GroupSizes, NegativePattern, NegativeSign, PositivePattern, ISOCode, ISOCodePattern, ExchangeRate, AutoUpdate, LastUpdate)");
                    insertQuery.Append(" VALUES (@StoreId, @Name, @CurrencySymbol, @DecimalDigits, @DecimalSeparator, @GroupSeparator, @GroupSizes, @NegativePattern, @NegativeSign, @PositivePattern, @ISOCode, @ISOCodePattern, @ExchangeRate, @AutoUpdate, @LastUpdate)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@CurrencyId", System.Data.DbType.Int32, this.CurrencyId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@CurrencySymbol", System.Data.DbType.String, NullableData.DbNullify(this.CurrencySymbol));
                        database.AddInParameter(insertCommand, "@DecimalDigits", System.Data.DbType.Int32, this.DecimalDigits);
                        database.AddInParameter(insertCommand, "@DecimalSeparator", System.Data.DbType.String, NullableData.DbNullify(this.DecimalSeparator));
                        database.AddInParameter(insertCommand, "@GroupSeparator", System.Data.DbType.String, NullableData.DbNullify(this.GroupSeparator));
                        database.AddInParameter(insertCommand, "@GroupSizes", System.Data.DbType.String, NullableData.DbNullify(this.GroupSizes));
                        database.AddInParameter(insertCommand, "@NegativePattern", System.Data.DbType.Byte, this.NegativePattern);
                        database.AddInParameter(insertCommand, "@NegativeSign", System.Data.DbType.String, NullableData.DbNullify(this.NegativeSign));
                        database.AddInParameter(insertCommand, "@PositivePattern", System.Data.DbType.Byte, this.PositivePattern);
                        database.AddInParameter(insertCommand, "@ISOCode", System.Data.DbType.String, this.ISOCode);
                        database.AddInParameter(insertCommand, "@ISOCodePattern", System.Data.DbType.Byte, NullableData.DbNullify(this.ISOCodePattern));
                        database.AddInParameter(insertCommand, "@ExchangeRate", System.Data.DbType.Decimal, this.ExchangeRate);
                        database.AddInParameter(insertCommand, "@AutoUpdate", System.Data.DbType.Boolean, this.AutoUpdate);
                        database.AddInParameter(insertCommand, "@LastUpdate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastUpdate)));
                        //RESULT IS NEW IDENTITY;
                        result           = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._CurrencyId = result;
                    }
                }

                //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);
        }
예제 #26
0
        /// <summary>
        /// Saves this OrderShipment 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;

                if (this.OrderShipmentId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_OrderShipments SET ");
                    updateQuery.Append("OrderId = @OrderId");
                    updateQuery.Append(", WarehouseId = @WarehouseId");
                    updateQuery.Append(", ShipToFirstName = @ShipToFirstName");
                    updateQuery.Append(", ShipToLastName = @ShipToLastName");
                    updateQuery.Append(", ShipToCompany = @ShipToCompany");
                    updateQuery.Append(", ShipToAddress1 = @ShipToAddress1");
                    updateQuery.Append(", ShipToAddress2 = @ShipToAddress2");
                    updateQuery.Append(", ShipToCity = @ShipToCity");
                    updateQuery.Append(", ShipToProvince = @ShipToProvince");
                    updateQuery.Append(", ShipToPostalCode = @ShipToPostalCode");
                    updateQuery.Append(", ShipToCountryCode = @ShipToCountryCode");
                    updateQuery.Append(", ShipToPhone = @ShipToPhone");
                    updateQuery.Append(", ShipToFax = @ShipToFax");
                    updateQuery.Append(", ShipToEmail = @ShipToEmail");
                    updateQuery.Append(", ShipToResidence = @ShipToResidence");
                    updateQuery.Append(", ShipMethodId = @ShipMethodId");
                    updateQuery.Append(", ShipMethodName = @ShipMethodName");
                    updateQuery.Append(", ShipMessage = @ShipMessage");
                    updateQuery.Append(", ShipDate = @ShipDate");
                    updateQuery.Append(" WHERE OrderShipmentId = @OrderShipmentId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@OrderShipmentId", System.Data.DbType.Int32, this.OrderShipmentId);
                        database.AddInParameter(updateCommand, "@OrderId", System.Data.DbType.Int32, this.OrderId);
                        database.AddInParameter(updateCommand, "@WarehouseId", System.Data.DbType.Int32, NullableData.DbNullify(this.WarehouseId));
                        database.AddInParameter(updateCommand, "@ShipToFirstName", System.Data.DbType.String, NullableData.DbNullify(this.ShipToFirstName));
                        database.AddInParameter(updateCommand, "@ShipToLastName", System.Data.DbType.String, NullableData.DbNullify(this.ShipToLastName));
                        database.AddInParameter(updateCommand, "@ShipToCompany", System.Data.DbType.String, NullableData.DbNullify(this.ShipToCompany));
                        database.AddInParameter(updateCommand, "@ShipToAddress1", System.Data.DbType.String, NullableData.DbNullify(this.ShipToAddress1));
                        database.AddInParameter(updateCommand, "@ShipToAddress2", System.Data.DbType.String, NullableData.DbNullify(this.ShipToAddress2));
                        database.AddInParameter(updateCommand, "@ShipToCity", System.Data.DbType.String, NullableData.DbNullify(this.ShipToCity));
                        database.AddInParameter(updateCommand, "@ShipToProvince", System.Data.DbType.String, NullableData.DbNullify(this.ShipToProvince));
                        database.AddInParameter(updateCommand, "@ShipToPostalCode", System.Data.DbType.String, NullableData.DbNullify(this.ShipToPostalCode));
                        database.AddInParameter(updateCommand, "@ShipToCountryCode", System.Data.DbType.String, NullableData.DbNullify(this.ShipToCountryCode));
                        database.AddInParameter(updateCommand, "@ShipToPhone", System.Data.DbType.String, NullableData.DbNullify(this.ShipToPhone));
                        database.AddInParameter(updateCommand, "@ShipToFax", System.Data.DbType.String, NullableData.DbNullify(this.ShipToFax));
                        database.AddInParameter(updateCommand, "@ShipToEmail", System.Data.DbType.String, NullableData.DbNullify(this.ShipToEmail));
                        database.AddInParameter(updateCommand, "@ShipToResidence", System.Data.DbType.Boolean, NullableData.DbNullify(this.ShipToResidence));
                        database.AddInParameter(updateCommand, "@ShipMethodId", System.Data.DbType.Int32, NullableData.DbNullify(this.ShipMethodId));
                        database.AddInParameter(updateCommand, "@ShipMethodName", System.Data.DbType.String, NullableData.DbNullify(this.ShipMethodName));
                        database.AddInParameter(updateCommand, "@ShipMessage", System.Data.DbType.String, NullableData.DbNullify(this.ShipMessage));
                        database.AddInParameter(updateCommand, "@ShipDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.ShipDate)));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_OrderShipments (OrderId, WarehouseId, ShipToFirstName, ShipToLastName, ShipToCompany, ShipToAddress1, ShipToAddress2, ShipToCity, ShipToProvince, ShipToPostalCode, ShipToCountryCode, ShipToPhone, ShipToFax, ShipToEmail, ShipToResidence, ShipMethodId, ShipMethodName, ShipMessage, ShipDate)");
                    insertQuery.Append(" VALUES (@OrderId, @WarehouseId, @ShipToFirstName, @ShipToLastName, @ShipToCompany, @ShipToAddress1, @ShipToAddress2, @ShipToCity, @ShipToProvince, @ShipToPostalCode, @ShipToCountryCode, @ShipToPhone, @ShipToFax, @ShipToEmail, @ShipToResidence, @ShipMethodId, @ShipMethodName, @ShipMessage, @ShipDate)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@OrderShipmentId", System.Data.DbType.Int32, this.OrderShipmentId);
                        database.AddInParameter(insertCommand, "@OrderId", System.Data.DbType.Int32, this.OrderId);
                        database.AddInParameter(insertCommand, "@WarehouseId", System.Data.DbType.Int32, NullableData.DbNullify(this.WarehouseId));
                        database.AddInParameter(insertCommand, "@ShipToFirstName", System.Data.DbType.String, NullableData.DbNullify(this.ShipToFirstName));
                        database.AddInParameter(insertCommand, "@ShipToLastName", System.Data.DbType.String, NullableData.DbNullify(this.ShipToLastName));
                        database.AddInParameter(insertCommand, "@ShipToCompany", System.Data.DbType.String, NullableData.DbNullify(this.ShipToCompany));
                        database.AddInParameter(insertCommand, "@ShipToAddress1", System.Data.DbType.String, NullableData.DbNullify(this.ShipToAddress1));
                        database.AddInParameter(insertCommand, "@ShipToAddress2", System.Data.DbType.String, NullableData.DbNullify(this.ShipToAddress2));
                        database.AddInParameter(insertCommand, "@ShipToCity", System.Data.DbType.String, NullableData.DbNullify(this.ShipToCity));
                        database.AddInParameter(insertCommand, "@ShipToProvince", System.Data.DbType.String, NullableData.DbNullify(this.ShipToProvince));
                        database.AddInParameter(insertCommand, "@ShipToPostalCode", System.Data.DbType.String, NullableData.DbNullify(this.ShipToPostalCode));
                        database.AddInParameter(insertCommand, "@ShipToCountryCode", System.Data.DbType.String, NullableData.DbNullify(this.ShipToCountryCode));
                        database.AddInParameter(insertCommand, "@ShipToPhone", System.Data.DbType.String, NullableData.DbNullify(this.ShipToPhone));
                        database.AddInParameter(insertCommand, "@ShipToFax", System.Data.DbType.String, NullableData.DbNullify(this.ShipToFax));
                        database.AddInParameter(insertCommand, "@ShipToEmail", System.Data.DbType.String, NullableData.DbNullify(this.ShipToEmail));
                        database.AddInParameter(insertCommand, "@ShipToResidence", System.Data.DbType.Boolean, NullableData.DbNullify(this.ShipToResidence));
                        database.AddInParameter(insertCommand, "@ShipMethodId", System.Data.DbType.Int32, NullableData.DbNullify(this.ShipMethodId));
                        database.AddInParameter(insertCommand, "@ShipMethodName", System.Data.DbType.String, NullableData.DbNullify(this.ShipMethodName));
                        database.AddInParameter(insertCommand, "@ShipMessage", System.Data.DbType.String, NullableData.DbNullify(this.ShipMessage));
                        database.AddInParameter(insertCommand, "@ShipDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.ShipDate)));
                        //RESULT IS NEW IDENTITY;
                        result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._OrderShipmentId = 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);
        }
예제 #27
0
        /// <summary>
        /// Saves this Affiliate 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.AffiliateId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Affiliates SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", Name = @Name");
                    updateQuery.Append(", PayeeName = @PayeeName");
                    updateQuery.Append(", FirstName = @FirstName");
                    updateQuery.Append(", LastName = @LastName");
                    updateQuery.Append(", Company = @Company");
                    updateQuery.Append(", Address1 = @Address1");
                    updateQuery.Append(", Address2 = @Address2");
                    updateQuery.Append(", City = @City");
                    updateQuery.Append(", Province = @Province");
                    updateQuery.Append(", PostalCode = @PostalCode");
                    updateQuery.Append(", CountryCode = @CountryCode");
                    updateQuery.Append(", PhoneNumber = @PhoneNumber");
                    updateQuery.Append(", FaxNumber = @FaxNumber");
                    updateQuery.Append(", MobileNumber = @MobileNumber");
                    updateQuery.Append(", WebsiteUrl = @WebsiteUrl");
                    updateQuery.Append(", Email = @Email");
                    updateQuery.Append(", CommissionRate = @CommissionRate");
                    updateQuery.Append(", CommissionIsPercent = @CommissionIsPercent");
                    updateQuery.Append(", CommissionOnTotal = @CommissionOnTotal");
                    updateQuery.Append(", ReferralPeriodId = @ReferralPeriodId");
                    updateQuery.Append(", ReferralDays = @ReferralDays");
                    updateQuery.Append(", GroupId = @GroupId");
                    updateQuery.Append(" WHERE AffiliateId = @AffiliateId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@AffiliateId", System.Data.DbType.Int32, this.AffiliateId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(updateCommand, "@PayeeName", System.Data.DbType.String, NullableData.DbNullify(this.PayeeName));
                        database.AddInParameter(updateCommand, "@FirstName", System.Data.DbType.String, NullableData.DbNullify(this.FirstName));
                        database.AddInParameter(updateCommand, "@LastName", System.Data.DbType.String, NullableData.DbNullify(this.LastName));
                        database.AddInParameter(updateCommand, "@Company", System.Data.DbType.String, NullableData.DbNullify(this.Company));
                        database.AddInParameter(updateCommand, "@Address1", System.Data.DbType.String, NullableData.DbNullify(this.Address1));
                        database.AddInParameter(updateCommand, "@Address2", System.Data.DbType.String, NullableData.DbNullify(this.Address2));
                        database.AddInParameter(updateCommand, "@City", System.Data.DbType.String, NullableData.DbNullify(this.City));
                        database.AddInParameter(updateCommand, "@Province", System.Data.DbType.String, NullableData.DbNullify(this.Province));
                        database.AddInParameter(updateCommand, "@PostalCode", System.Data.DbType.String, NullableData.DbNullify(this.PostalCode));
                        database.AddInParameter(updateCommand, "@CountryCode", System.Data.DbType.String, NullableData.DbNullify(this.CountryCode));
                        database.AddInParameter(updateCommand, "@PhoneNumber", System.Data.DbType.String, NullableData.DbNullify(this.PhoneNumber));
                        database.AddInParameter(updateCommand, "@FaxNumber", System.Data.DbType.String, NullableData.DbNullify(this.FaxNumber));
                        database.AddInParameter(updateCommand, "@MobileNumber", System.Data.DbType.String, NullableData.DbNullify(this.MobileNumber));
                        database.AddInParameter(updateCommand, "@WebsiteUrl", System.Data.DbType.String, NullableData.DbNullify(this.WebsiteUrl));
                        database.AddInParameter(updateCommand, "@Email", System.Data.DbType.String, NullableData.DbNullify(this.Email));
                        database.AddInParameter(updateCommand, "@CommissionRate", System.Data.DbType.Decimal, this.CommissionRate);
                        database.AddInParameter(updateCommand, "@CommissionIsPercent", System.Data.DbType.Boolean, this.CommissionIsPercent);
                        database.AddInParameter(updateCommand, "@CommissionOnTotal", System.Data.DbType.Boolean, this.CommissionOnTotal);
                        database.AddInParameter(updateCommand, "@ReferralPeriodId", System.Data.DbType.Byte, this.ReferralPeriodId);
                        database.AddInParameter(updateCommand, "@ReferralDays", System.Data.DbType.Int16, this.ReferralDays);
                        database.AddInParameter(updateCommand, "@GroupId", System.Data.DbType.Int32, NullableData.DbNullify(this.GroupId));
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Affiliates (StoreId, Name, PayeeName, FirstName, LastName, Company, Address1, Address2, City, Province, PostalCode, CountryCode, PhoneNumber, FaxNumber, MobileNumber, WebsiteUrl, Email, CommissionRate, CommissionIsPercent, CommissionOnTotal, ReferralPeriodId, ReferralDays, GroupId)");
                    insertQuery.Append(" VALUES (@StoreId, @Name, @PayeeName, @FirstName, @LastName, @Company, @Address1, @Address2, @City, @Province, @PostalCode, @CountryCode, @PhoneNumber, @FaxNumber, @MobileNumber, @WebsiteUrl, @Email, @CommissionRate, @CommissionIsPercent, @CommissionOnTotal, @ReferralPeriodId, @ReferralDays, @GroupId)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@AffiliateId", System.Data.DbType.Int32, this.AffiliateId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name);
                        database.AddInParameter(insertCommand, "@PayeeName", System.Data.DbType.String, NullableData.DbNullify(this.PayeeName));
                        database.AddInParameter(insertCommand, "@FirstName", System.Data.DbType.String, NullableData.DbNullify(this.FirstName));
                        database.AddInParameter(insertCommand, "@LastName", System.Data.DbType.String, NullableData.DbNullify(this.LastName));
                        database.AddInParameter(insertCommand, "@Company", System.Data.DbType.String, NullableData.DbNullify(this.Company));
                        database.AddInParameter(insertCommand, "@Address1", System.Data.DbType.String, NullableData.DbNullify(this.Address1));
                        database.AddInParameter(insertCommand, "@Address2", System.Data.DbType.String, NullableData.DbNullify(this.Address2));
                        database.AddInParameter(insertCommand, "@City", System.Data.DbType.String, NullableData.DbNullify(this.City));
                        database.AddInParameter(insertCommand, "@Province", System.Data.DbType.String, NullableData.DbNullify(this.Province));
                        database.AddInParameter(insertCommand, "@PostalCode", System.Data.DbType.String, NullableData.DbNullify(this.PostalCode));
                        database.AddInParameter(insertCommand, "@CountryCode", System.Data.DbType.String, NullableData.DbNullify(this.CountryCode));
                        database.AddInParameter(insertCommand, "@PhoneNumber", System.Data.DbType.String, NullableData.DbNullify(this.PhoneNumber));
                        database.AddInParameter(insertCommand, "@FaxNumber", System.Data.DbType.String, NullableData.DbNullify(this.FaxNumber));
                        database.AddInParameter(insertCommand, "@MobileNumber", System.Data.DbType.String, NullableData.DbNullify(this.MobileNumber));
                        database.AddInParameter(insertCommand, "@WebsiteUrl", System.Data.DbType.String, NullableData.DbNullify(this.WebsiteUrl));
                        database.AddInParameter(insertCommand, "@Email", System.Data.DbType.String, NullableData.DbNullify(this.Email));
                        database.AddInParameter(insertCommand, "@CommissionRate", System.Data.DbType.Decimal, this.CommissionRate);
                        database.AddInParameter(insertCommand, "@CommissionIsPercent", System.Data.DbType.Boolean, this.CommissionIsPercent);
                        database.AddInParameter(insertCommand, "@CommissionOnTotal", System.Data.DbType.Boolean, this.CommissionOnTotal);
                        database.AddInParameter(insertCommand, "@ReferralPeriodId", System.Data.DbType.Byte, this.ReferralPeriodId);
                        database.AddInParameter(insertCommand, "@ReferralDays", System.Data.DbType.Int16, this.ReferralDays);
                        database.AddInParameter(insertCommand, "@GroupId", System.Data.DbType.Int32, NullableData.DbNullify(this.GroupId));
                        //RESULT IS NEW IDENTITY;
                        result            = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._AffiliateId = 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);
        }
        /// <summary>
        /// Saves this ProductImage 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;

                if (this.ProductImageId == 0)
                {
                    recordExists = false;
                }

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

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_ProductImages SET ");
                    updateQuery.Append("ProductId = @ProductId");
                    updateQuery.Append(", ImageUrl = @ImageUrl");
                    updateQuery.Append(", ImageAltText = @ImageAltText");
                    updateQuery.Append(", OrderBy = @OrderBy");
                    updateQuery.Append(" WHERE ProductImageId = @ProductImageId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@ProductImageId", System.Data.DbType.Int32, this.ProductImageId);
                        database.AddInParameter(updateCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId);
                        database.AddInParameter(updateCommand, "@ImageUrl", System.Data.DbType.String, this.ImageUrl);
                        database.AddInParameter(updateCommand, "@ImageAltText", System.Data.DbType.String, NullableData.DbNullify(this.ImageAltText));
                        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_ProductImages (ProductId, ImageUrl, ImageAltText, OrderBy)");
                    insertQuery.Append(" VALUES (@ProductId, @ImageUrl, @ImageAltText, @OrderBy)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@ProductImageId", System.Data.DbType.Int32, this.ProductImageId);
                        database.AddInParameter(insertCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId);
                        database.AddInParameter(insertCommand, "@ImageUrl", System.Data.DbType.String, this.ImageUrl);
                        database.AddInParameter(insertCommand, "@ImageAltText", System.Data.DbType.String, NullableData.DbNullify(this.ImageAltText));
                        database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy);
                        //RESULT IS NEW IDENTITY;
                        result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._ProductImageId = result;
                    }
                }

                //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);
        }
예제 #29
0
        /// <summary>
        /// Saves this PageView 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.PageViewId == 0)
                {
                    recordExists = false;
                }

                //SET DEFAULT FOR DATE FIELD
                if (this.ActivityDate == System.DateTime.MinValue)
                {
                    this.ActivityDate = LocaleHelper.LocalNow;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_PageViews SET ");
                    updateQuery.Append("StoreId = @StoreId");
                    updateQuery.Append(", ActivityDate = @ActivityDate");
                    updateQuery.Append(", RemoteIP = @RemoteIP");
                    updateQuery.Append(", RequestMethod = @RequestMethod");
                    updateQuery.Append(", UserId = @UserId");
                    updateQuery.Append(", UriStem = @UriStem");
                    updateQuery.Append(", UriQuery = @UriQuery");
                    updateQuery.Append(", TimeTaken = @TimeTaken");
                    updateQuery.Append(", UserAgent = @UserAgent");
                    updateQuery.Append(", Referrer = @Referrer");
                    updateQuery.Append(", CatalogNodeId = @CatalogNodeId");
                    updateQuery.Append(", CatalogNodeTypeId = @CatalogNodeTypeId");
                    updateQuery.Append(", Browser = @Browser");
                    updateQuery.Append(", BrowserName = @BrowserName");
                    updateQuery.Append(", BrowserPlatform = @BrowserPlatform");
                    updateQuery.Append(", BrowserVersion = @BrowserVersion");
                    updateQuery.Append(", AffiliateId = @AffiliateId");
                    updateQuery.Append(" WHERE PageViewId = @PageViewId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@PageViewId", System.Data.DbType.Int32, this.PageViewId);
                        database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(updateCommand, "@ActivityDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.ActivityDate));
                        database.AddInParameter(updateCommand, "@RemoteIP", System.Data.DbType.String, this.RemoteIP);
                        database.AddInParameter(updateCommand, "@RequestMethod", System.Data.DbType.String, this.RequestMethod);
                        database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(updateCommand, "@UriStem", System.Data.DbType.String, this.UriStem);
                        database.AddInParameter(updateCommand, "@UriQuery", System.Data.DbType.String, NullableData.DbNullify(this.UriQuery));
                        database.AddInParameter(updateCommand, "@TimeTaken", System.Data.DbType.Int32, this.TimeTaken);
                        database.AddInParameter(updateCommand, "@UserAgent", System.Data.DbType.String, NullableData.DbNullify(this.UserAgent));
                        database.AddInParameter(updateCommand, "@Referrer", System.Data.DbType.String, NullableData.DbNullify(this.Referrer));
                        database.AddInParameter(updateCommand, "@CatalogNodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.CatalogNodeId));
                        database.AddInParameter(updateCommand, "@CatalogNodeTypeId", System.Data.DbType.Int16, NullableData.DbNullify(this.CatalogNodeTypeId));
                        database.AddInParameter(updateCommand, "@Browser", System.Data.DbType.String, this.Browser);
                        database.AddInParameter(updateCommand, "@BrowserName", System.Data.DbType.String, this.BrowserName);
                        database.AddInParameter(updateCommand, "@BrowserPlatform", System.Data.DbType.String, this.BrowserPlatform);
                        database.AddInParameter(updateCommand, "@BrowserVersion", System.Data.DbType.String, this.BrowserVersion);
                        database.AddInParameter(updateCommand, "@AffiliateId", System.Data.DbType.Int32, this.AffiliateId);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_PageViews (StoreId, ActivityDate, RemoteIP, RequestMethod, UserId, UriStem, UriQuery, TimeTaken, UserAgent, Referrer, CatalogNodeId, CatalogNodeTypeId, Browser, BrowserName, BrowserPlatform, BrowserVersion, AffiliateId)");
                    insertQuery.Append(" VALUES (@StoreId, @ActivityDate, @RemoteIP, @RequestMethod, @UserId, @UriStem, @UriQuery, @TimeTaken, @UserAgent, @Referrer, @CatalogNodeId, @CatalogNodeTypeId, @Browser, @BrowserName, @BrowserPlatform, @BrowserVersion, @AffiliateId)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@PageViewId", System.Data.DbType.Int32, this.PageViewId);
                        database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId);
                        database.AddInParameter(insertCommand, "@ActivityDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.ActivityDate));
                        database.AddInParameter(insertCommand, "@RemoteIP", System.Data.DbType.String, this.RemoteIP);
                        database.AddInParameter(insertCommand, "@RequestMethod", System.Data.DbType.String, this.RequestMethod);
                        database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(insertCommand, "@UriStem", System.Data.DbType.String, this.UriStem);
                        database.AddInParameter(insertCommand, "@UriQuery", System.Data.DbType.String, NullableData.DbNullify(this.UriQuery));
                        database.AddInParameter(insertCommand, "@TimeTaken", System.Data.DbType.Int32, this.TimeTaken);
                        database.AddInParameter(insertCommand, "@UserAgent", System.Data.DbType.String, NullableData.DbNullify(this.UserAgent));
                        database.AddInParameter(insertCommand, "@Referrer", System.Data.DbType.String, NullableData.DbNullify(this.Referrer));
                        database.AddInParameter(insertCommand, "@CatalogNodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.CatalogNodeId));
                        database.AddInParameter(insertCommand, "@CatalogNodeTypeId", System.Data.DbType.Int16, NullableData.DbNullify(this.CatalogNodeTypeId));
                        database.AddInParameter(insertCommand, "@Browser", System.Data.DbType.String, this.Browser);
                        database.AddInParameter(insertCommand, "@BrowserName", System.Data.DbType.String, this.BrowserName);
                        database.AddInParameter(insertCommand, "@BrowserPlatform", System.Data.DbType.String, this.BrowserPlatform);
                        database.AddInParameter(insertCommand, "@BrowserVersion", System.Data.DbType.String, this.BrowserVersion);
                        database.AddInParameter(insertCommand, "@AffiliateId", System.Data.DbType.Int32, this.AffiliateId);
                        //RESULT IS NEW IDENTITY;
                        result           = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._PageViewId = result;
                    }
                }

                //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);
        }
예제 #30
0
        /// <summary>
        /// Saves this Address 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;

                if (this.AddressId == 0)
                {
                    recordExists = false;
                }

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

                int result = 0;
                if (recordExists)
                {
                    //UPDATE
                    StringBuilder updateQuery = new StringBuilder();
                    updateQuery.Append("UPDATE ac_Addresses SET ");
                    updateQuery.Append("UserId = @UserId");
                    updateQuery.Append(", Nickname = @Nickname");
                    updateQuery.Append(", FirstName = @FirstName");
                    updateQuery.Append(", LastName = @LastName");
                    updateQuery.Append(", Company = @Company");
                    updateQuery.Append(", Address1 = @Address1");
                    updateQuery.Append(", Address2 = @Address2");
                    updateQuery.Append(", City = @City");
                    updateQuery.Append(", Province = @Province");
                    updateQuery.Append(", PostalCode = @PostalCode");
                    updateQuery.Append(", CountryCode = @CountryCode");
                    updateQuery.Append(", Phone = @Phone");
                    updateQuery.Append(", Fax = @Fax");
                    updateQuery.Append(", Email = @Email");
                    updateQuery.Append(", Residence = @Residence");
                    updateQuery.Append(", Validated = @Validated");
                    updateQuery.Append(" WHERE AddressId = @AddressId");
                    using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString()))
                    {
                        database.AddInParameter(updateCommand, "@AddressId", System.Data.DbType.Int32, this.AddressId);
                        database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(updateCommand, "@Nickname", System.Data.DbType.String, NullableData.DbNullify(this.Nickname));
                        database.AddInParameter(updateCommand, "@FirstName", System.Data.DbType.String, NullableData.DbNullify(this.FirstName));
                        database.AddInParameter(updateCommand, "@LastName", System.Data.DbType.String, NullableData.DbNullify(this.LastName));
                        database.AddInParameter(updateCommand, "@Company", System.Data.DbType.String, NullableData.DbNullify(this.Company));
                        database.AddInParameter(updateCommand, "@Address1", System.Data.DbType.String, NullableData.DbNullify(this.Address1));
                        database.AddInParameter(updateCommand, "@Address2", System.Data.DbType.String, NullableData.DbNullify(this.Address2));
                        database.AddInParameter(updateCommand, "@City", System.Data.DbType.String, NullableData.DbNullify(this.City));
                        database.AddInParameter(updateCommand, "@Province", System.Data.DbType.String, NullableData.DbNullify(this.Province));
                        database.AddInParameter(updateCommand, "@PostalCode", System.Data.DbType.String, NullableData.DbNullify(this.PostalCode));
                        database.AddInParameter(updateCommand, "@CountryCode", System.Data.DbType.String, NullableData.DbNullify(this.CountryCode));
                        database.AddInParameter(updateCommand, "@Phone", System.Data.DbType.String, NullableData.DbNullify(this.Phone));
                        database.AddInParameter(updateCommand, "@Fax", System.Data.DbType.String, NullableData.DbNullify(this.Fax));
                        database.AddInParameter(updateCommand, "@Email", System.Data.DbType.String, NullableData.DbNullify(this.Email));
                        database.AddInParameter(updateCommand, "@Residence", System.Data.DbType.Boolean, this.Residence);
                        database.AddInParameter(updateCommand, "@Validated", System.Data.DbType.Boolean, this.Validated);
                        //RESULT IS NUMBER OF RECORDS AFFECTED
                        result = database.ExecuteNonQuery(updateCommand);
                    }
                }
                else
                {
                    //INSERT
                    StringBuilder insertQuery = new StringBuilder();
                    insertQuery.Append("INSERT INTO ac_Addresses (UserId, Nickname, FirstName, LastName, Company, Address1, Address2, City, Province, PostalCode, CountryCode, Phone, Fax, Email, Residence, Validated)");
                    insertQuery.Append(" VALUES (@UserId, @Nickname, @FirstName, @LastName, @Company, @Address1, @Address2, @City, @Province, @PostalCode, @CountryCode, @Phone, @Fax, @Email, @Residence, @Validated)");
                    insertQuery.Append("; SELECT Scope_Identity()");
                    using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString()))
                    {
                        database.AddInParameter(insertCommand, "@AddressId", System.Data.DbType.Int32, this.AddressId);
                        database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, this.UserId);
                        database.AddInParameter(insertCommand, "@Nickname", System.Data.DbType.String, NullableData.DbNullify(this.Nickname));
                        database.AddInParameter(insertCommand, "@FirstName", System.Data.DbType.String, NullableData.DbNullify(this.FirstName));
                        database.AddInParameter(insertCommand, "@LastName", System.Data.DbType.String, NullableData.DbNullify(this.LastName));
                        database.AddInParameter(insertCommand, "@Company", System.Data.DbType.String, NullableData.DbNullify(this.Company));
                        database.AddInParameter(insertCommand, "@Address1", System.Data.DbType.String, NullableData.DbNullify(this.Address1));
                        database.AddInParameter(insertCommand, "@Address2", System.Data.DbType.String, NullableData.DbNullify(this.Address2));
                        database.AddInParameter(insertCommand, "@City", System.Data.DbType.String, NullableData.DbNullify(this.City));
                        database.AddInParameter(insertCommand, "@Province", System.Data.DbType.String, NullableData.DbNullify(this.Province));
                        database.AddInParameter(insertCommand, "@PostalCode", System.Data.DbType.String, NullableData.DbNullify(this.PostalCode));
                        database.AddInParameter(insertCommand, "@CountryCode", System.Data.DbType.String, NullableData.DbNullify(this.CountryCode));
                        database.AddInParameter(insertCommand, "@Phone", System.Data.DbType.String, NullableData.DbNullify(this.Phone));
                        database.AddInParameter(insertCommand, "@Fax", System.Data.DbType.String, NullableData.DbNullify(this.Fax));
                        database.AddInParameter(insertCommand, "@Email", System.Data.DbType.String, NullableData.DbNullify(this.Email));
                        database.AddInParameter(insertCommand, "@Residence", System.Data.DbType.Boolean, this.Residence);
                        database.AddInParameter(insertCommand, "@Validated", System.Data.DbType.Boolean, this.Validated);
                        //RESULT IS NEW IDENTITY;
                        result          = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand));
                        this._AddressId = 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);
        }