protected void DateRageList_SelectedIndexChanged(object sender, EventArgs e) { DateTime localNow = LocaleHelper.LocalNow; int days = AlwaysConvert.ToInt(DateRageList.SelectedValue); DateTime lastDayStart = LocaleHelper.FromLocalTime(localNow.AddDays(-1 * days)); lastDayStart = new DateTime(lastDayStart.Year, lastDayStart.Month, lastDayStart.Day, 0, 0, 0); BindOrderSummaryGrid(lastDayStart); }
/// <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); }
/// <summary> /// Saves this Transaction 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.TransactionId == 0) { recordExists = false; } //SET DEFAULT FOR DATE FIELD if (this.TransactionDate == System.DateTime.MinValue) { this.TransactionDate = LocaleHelper.LocalNow; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_Transactions"); selectQuery.Append(" WHERE TransactionId = @TransactionId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@TransactionId", System.Data.DbType.Int32, this.TransactionId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_Transactions SET "); updateQuery.Append("TransactionTypeId = @TransactionTypeId"); updateQuery.Append(", PaymentId = @PaymentId"); updateQuery.Append(", PaymentGatewayId = @PaymentGatewayId"); updateQuery.Append(", ProviderTransactionId = @ProviderTransactionId"); updateQuery.Append(", TransactionDate = @TransactionDate"); updateQuery.Append(", Amount = @Amount"); updateQuery.Append(", TransactionStatusId = @TransactionStatusId"); updateQuery.Append(", ResponseCode = @ResponseCode"); updateQuery.Append(", ResponseMessage = @ResponseMessage"); updateQuery.Append(", AuthorizationCode = @AuthorizationCode"); updateQuery.Append(", AVSResultCode = @AVSResultCode"); updateQuery.Append(", CVVResultCode = @CVVResultCode"); updateQuery.Append(", CAVResultCode = @CAVResultCode"); updateQuery.Append(", RemoteIP = @RemoteIP"); updateQuery.Append(", Referrer = @Referrer"); updateQuery.Append(", AdditionalData = @AdditionalData"); updateQuery.Append(" WHERE TransactionId = @TransactionId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@TransactionId", System.Data.DbType.Int32, this.TransactionId); database.AddInParameter(updateCommand, "@TransactionTypeId", System.Data.DbType.Int16, this.TransactionTypeId); database.AddInParameter(updateCommand, "@PaymentId", System.Data.DbType.Int32, this.PaymentId); database.AddInParameter(updateCommand, "@PaymentGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.PaymentGatewayId)); database.AddInParameter(updateCommand, "@ProviderTransactionId", System.Data.DbType.String, NullableData.DbNullify(this.ProviderTransactionId)); database.AddInParameter(updateCommand, "@TransactionDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.TransactionDate)); database.AddInParameter(updateCommand, "@Amount", System.Data.DbType.Decimal, this.Amount); database.AddInParameter(updateCommand, "@TransactionStatusId", System.Data.DbType.Int16, this.TransactionStatusId); database.AddInParameter(updateCommand, "@ResponseCode", System.Data.DbType.String, NullableData.DbNullify(this.ResponseCode)); database.AddInParameter(updateCommand, "@ResponseMessage", System.Data.DbType.String, NullableData.DbNullify(this.ResponseMessage)); database.AddInParameter(updateCommand, "@AuthorizationCode", System.Data.DbType.String, NullableData.DbNullify(this.AuthorizationCode)); database.AddInParameter(updateCommand, "@AVSResultCode", System.Data.DbType.String, NullableData.DbNullify(this.AVSResultCode)); database.AddInParameter(updateCommand, "@CVVResultCode", System.Data.DbType.String, NullableData.DbNullify(this.CVVResultCode)); database.AddInParameter(updateCommand, "@CAVResultCode", System.Data.DbType.String, NullableData.DbNullify(this.CAVResultCode)); database.AddInParameter(updateCommand, "@RemoteIP", System.Data.DbType.String, NullableData.DbNullify(this.RemoteIP)); database.AddInParameter(updateCommand, "@Referrer", System.Data.DbType.String, NullableData.DbNullify(this.Referrer)); database.AddInParameter(updateCommand, "@AdditionalData", System.Data.DbType.String, NullableData.DbNullify(this.AdditionalData)); //RESULT IS NUMBER OF RECORDS AFFECTED result = database.ExecuteNonQuery(updateCommand); } } else { //INSERT StringBuilder insertQuery = new StringBuilder(); insertQuery.Append("INSERT INTO ac_Transactions (TransactionTypeId, PaymentId, PaymentGatewayId, ProviderTransactionId, TransactionDate, Amount, TransactionStatusId, ResponseCode, ResponseMessage, AuthorizationCode, AVSResultCode, CVVResultCode, CAVResultCode, RemoteIP, Referrer, AdditionalData)"); insertQuery.Append(" VALUES (@TransactionTypeId, @PaymentId, @PaymentGatewayId, @ProviderTransactionId, @TransactionDate, @Amount, @TransactionStatusId, @ResponseCode, @ResponseMessage, @AuthorizationCode, @AVSResultCode, @CVVResultCode, @CAVResultCode, @RemoteIP, @Referrer, @AdditionalData)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@TransactionId", System.Data.DbType.Int32, this.TransactionId); database.AddInParameter(insertCommand, "@TransactionTypeId", System.Data.DbType.Int16, this.TransactionTypeId); database.AddInParameter(insertCommand, "@PaymentId", System.Data.DbType.Int32, this.PaymentId); database.AddInParameter(insertCommand, "@PaymentGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(this.PaymentGatewayId)); database.AddInParameter(insertCommand, "@ProviderTransactionId", System.Data.DbType.String, NullableData.DbNullify(this.ProviderTransactionId)); database.AddInParameter(insertCommand, "@TransactionDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.TransactionDate)); database.AddInParameter(insertCommand, "@Amount", System.Data.DbType.Decimal, this.Amount); database.AddInParameter(insertCommand, "@TransactionStatusId", System.Data.DbType.Int16, this.TransactionStatusId); database.AddInParameter(insertCommand, "@ResponseCode", System.Data.DbType.String, NullableData.DbNullify(this.ResponseCode)); database.AddInParameter(insertCommand, "@ResponseMessage", System.Data.DbType.String, NullableData.DbNullify(this.ResponseMessage)); database.AddInParameter(insertCommand, "@AuthorizationCode", System.Data.DbType.String, NullableData.DbNullify(this.AuthorizationCode)); database.AddInParameter(insertCommand, "@AVSResultCode", System.Data.DbType.String, NullableData.DbNullify(this.AVSResultCode)); database.AddInParameter(insertCommand, "@CVVResultCode", System.Data.DbType.String, NullableData.DbNullify(this.CVVResultCode)); database.AddInParameter(insertCommand, "@CAVResultCode", System.Data.DbType.String, NullableData.DbNullify(this.CAVResultCode)); database.AddInParameter(insertCommand, "@RemoteIP", System.Data.DbType.String, NullableData.DbNullify(this.RemoteIP)); database.AddInParameter(insertCommand, "@Referrer", System.Data.DbType.String, NullableData.DbNullify(this.Referrer)); database.AddInParameter(insertCommand, "@AdditionalData", System.Data.DbType.String, NullableData.DbNullify(this.AdditionalData)); //RESULT IS NEW IDENTITY; result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand)); this._TransactionId = 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 BasketCoupon 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.AppliedDate == System.DateTime.MinValue) { this.AppliedDate = LocaleHelper.LocalNow; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_BasketCoupons"); selectQuery.Append(" WHERE BasketId = @BasketId AND CouponId = @CouponId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@BasketId", System.Data.DbType.Int32, this.BasketId); database.AddInParameter(selectCommand, "@CouponId", System.Data.DbType.Int32, this.CouponId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_BasketCoupons SET "); updateQuery.Append("AppliedDate = @AppliedDate"); updateQuery.Append(" WHERE BasketId = @BasketId AND CouponId = @CouponId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@BasketId", System.Data.DbType.Int32, this.BasketId); database.AddInParameter(updateCommand, "@CouponId", System.Data.DbType.Int32, this.CouponId); database.AddInParameter(updateCommand, "@AppliedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.AppliedDate)); //RESULT IS NUMBER OF RECORDS AFFECTED result = database.ExecuteNonQuery(updateCommand); } } else { //INSERT StringBuilder insertQuery = new StringBuilder(); insertQuery.Append("INSERT INTO ac_BasketCoupons (BasketId, CouponId, AppliedDate)"); insertQuery.Append(" VALUES (@BasketId, @CouponId, @AppliedDate)"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@BasketId", System.Data.DbType.Int32, this.BasketId); database.AddInParameter(insertCommand, "@CouponId", System.Data.DbType.Int32, this.CouponId); database.AddInParameter(insertCommand, "@AppliedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.AppliedDate)); //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 EmailList 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.EmailListId == 0) { recordExists = false; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_EmailLists"); selectQuery.Append(" WHERE EmailListId = @EmailListId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@EmailListId", System.Data.DbType.Int32, this.EmailListId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_EmailLists SET "); updateQuery.Append("StoreId = @StoreId"); updateQuery.Append(", Name = @Name"); updateQuery.Append(", Description = @Description"); updateQuery.Append(", IsPublic = @IsPublic"); updateQuery.Append(", SignupRuleId = @SignupRuleId"); updateQuery.Append(", SignupEmailTemplateId = @SignupEmailTemplateId"); updateQuery.Append(", LastSendDate = @LastSendDate"); updateQuery.Append(" WHERE EmailListId = @EmailListId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@EmailListId", System.Data.DbType.Int32, this.EmailListId); database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId); database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name); database.AddInParameter(updateCommand, "@Description", System.Data.DbType.String, NullableData.DbNullify(this.Description)); database.AddInParameter(updateCommand, "@IsPublic", System.Data.DbType.Boolean, this.IsPublic); database.AddInParameter(updateCommand, "@SignupRuleId", System.Data.DbType.Int16, this.SignupRuleId); database.AddInParameter(updateCommand, "@SignupEmailTemplateId", System.Data.DbType.Int32, NullableData.DbNullify(this.SignupEmailTemplateId)); database.AddInParameter(updateCommand, "@LastSendDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastSendDate))); //RESULT IS NUMBER OF RECORDS AFFECTED result = database.ExecuteNonQuery(updateCommand); } } else { //INSERT StringBuilder insertQuery = new StringBuilder(); insertQuery.Append("INSERT INTO ac_EmailLists (StoreId, Name, Description, IsPublic, SignupRuleId, SignupEmailTemplateId, LastSendDate)"); insertQuery.Append(" VALUES (@StoreId, @Name, @Description, @IsPublic, @SignupRuleId, @SignupEmailTemplateId, @LastSendDate)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@EmailListId", System.Data.DbType.Int32, this.EmailListId); database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId); database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name); database.AddInParameter(insertCommand, "@Description", System.Data.DbType.String, NullableData.DbNullify(this.Description)); database.AddInParameter(insertCommand, "@IsPublic", System.Data.DbType.Boolean, this.IsPublic); database.AddInParameter(insertCommand, "@SignupRuleId", System.Data.DbType.Int16, this.SignupRuleId); database.AddInParameter(insertCommand, "@SignupEmailTemplateId", System.Data.DbType.Int32, NullableData.DbNullify(this.SignupEmailTemplateId)); database.AddInParameter(insertCommand, "@LastSendDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastSendDate))); //RESULT IS NEW IDENTITY; result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand)); this._EmailListId = 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 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); }
/// <summary> /// Get the total count of order for specified user associated with specifed affiliate /// </summary> /// <param name="affiliateId"></param> /// <param name="userId"></param> /// <param name="referralDate"></param> /// <returns>Number of orders user has with specified affiliate</returns> public static int GetOrderCountForUser(int affiliateId, int userId, DateTime referralDate) { Database database = Token.Instance.Database; StringBuilder sql = new StringBuilder(); sql.Append("SELECT COUNT(OrderId) AS OrderCount"); sql.Append(" FROM ac_Orders"); sql.Append(" WHERE UserId = @userId AND AffiliateId = @affiliateId"); if (referralDate > DateTime.MinValue) { sql.Append(" AND OrderDate >= @referralDate"); } DbCommand selectCommand = database.GetSqlStringCommand(sql.ToString()); database.AddInParameter(selectCommand, "@userId", System.Data.DbType.Int32, userId); database.AddInParameter(selectCommand, "@affiliateId", System.Data.DbType.Int32, affiliateId); if (referralDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@referralDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(referralDate)); } return(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 Subscription 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.SubscriptionId == 0) { recordExists = false; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_Subscriptions"); selectQuery.Append(" WHERE SubscriptionId = @SubscriptionId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@SubscriptionId", System.Data.DbType.Int32, this.SubscriptionId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_Subscriptions SET "); updateQuery.Append("ProductId = @ProductId"); updateQuery.Append(", UserId = @UserId"); updateQuery.Append(", OrderItemId = @OrderItemId"); updateQuery.Append(", TransactionId = @TransactionId"); updateQuery.Append(", IsActive = @IsActive"); updateQuery.Append(", ExpirationDate = @ExpirationDate"); updateQuery.Append(", GroupId = @GroupId"); updateQuery.Append(" WHERE SubscriptionId = @SubscriptionId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@SubscriptionId", System.Data.DbType.Int32, this.SubscriptionId); database.AddInParameter(updateCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId); database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, this.UserId); database.AddInParameter(updateCommand, "@OrderItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.OrderItemId)); database.AddInParameter(updateCommand, "@TransactionId", System.Data.DbType.Int32, NullableData.DbNullify(this.TransactionId)); database.AddInParameter(updateCommand, "@IsActive", System.Data.DbType.Boolean, this.IsActive); database.AddInParameter(updateCommand, "@ExpirationDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.ExpirationDate))); 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_Subscriptions (ProductId, UserId, OrderItemId, TransactionId, IsActive, ExpirationDate, GroupId)"); insertQuery.Append(" VALUES (@ProductId, @UserId, @OrderItemId, @TransactionId, @IsActive, @ExpirationDate, @GroupId)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@SubscriptionId", System.Data.DbType.Int32, this.SubscriptionId); database.AddInParameter(insertCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId); database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, this.UserId); database.AddInParameter(insertCommand, "@OrderItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.OrderItemId)); database.AddInParameter(insertCommand, "@TransactionId", System.Data.DbType.Int32, NullableData.DbNullify(this.TransactionId)); database.AddInParameter(insertCommand, "@IsActive", System.Data.DbType.Boolean, this.IsActive); database.AddInParameter(insertCommand, "@ExpirationDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.ExpirationDate))); database.AddInParameter(insertCommand, "@GroupId", System.Data.DbType.Int32, NullableData.DbNullify(this.GroupId)); //RESULT IS NEW IDENTITY; result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand)); this._SubscriptionId = 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 UserPersonalization 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.LastUpdatedDate == System.DateTime.MinValue) { this.LastUpdatedDate = LocaleHelper.LocalNow; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_UserPersonalization"); selectQuery.Append(" WHERE PersonalizationPathId = @PersonalizationPathId AND UserId = @UserId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@PersonalizationPathId", System.Data.DbType.Int32, this.PersonalizationPathId); 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_UserPersonalization SET "); updateQuery.Append("PageSettings = @PageSettings"); updateQuery.Append(", Theme = @Theme"); updateQuery.Append(", MasterPageFile = @MasterPageFile"); updateQuery.Append(", LastUpdatedDate = @LastUpdatedDate"); updateQuery.Append(" WHERE PersonalizationPathId = @PersonalizationPathId AND UserId = @UserId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@PersonalizationPathId", System.Data.DbType.Int32, this.PersonalizationPathId); database.AddInParameter(updateCommand, "@UserId", System.Data.DbType.Int32, this.UserId); database.AddInParameter(updateCommand, "@PageSettings", System.Data.DbType.Binary, NullableData.DbNullify(this.PageSettings)); database.AddInParameter(updateCommand, "@Theme", System.Data.DbType.String, NullableData.DbNullify(this.Theme)); database.AddInParameter(updateCommand, "@MasterPageFile", System.Data.DbType.String, NullableData.DbNullify(this.MasterPageFile)); database.AddInParameter(updateCommand, "@LastUpdatedDate", System.Data.DbType.DateTime, 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_UserPersonalization (PersonalizationPathId, UserId, PageSettings, Theme, MasterPageFile, LastUpdatedDate)"); insertQuery.Append(" VALUES (@PersonalizationPathId, @UserId, @PageSettings, @Theme, @MasterPageFile, @LastUpdatedDate)"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@PersonalizationPathId", System.Data.DbType.Int32, this.PersonalizationPathId); database.AddInParameter(insertCommand, "@UserId", System.Data.DbType.Int32, this.UserId); database.AddInParameter(insertCommand, "@PageSettings", System.Data.DbType.Binary, NullableData.DbNullify(this.PageSettings)); database.AddInParameter(insertCommand, "@Theme", System.Data.DbType.String, NullableData.DbNullify(this.Theme)); database.AddInParameter(insertCommand, "@MasterPageFile", System.Data.DbType.String, NullableData.DbNullify(this.MasterPageFile)); database.AddInParameter(insertCommand, "@LastUpdatedDate", System.Data.DbType.DateTime, 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); }
/// <summary> /// Saves this Redirect 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.RedirectId == 0) { recordExists = false; } if (this.OrderBy < 0) { this.OrderBy = RedirectDataSource.GetNextOrderBy(); } //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_Redirects"); selectQuery.Append(" WHERE RedirectId = @redirectId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@RedirectId", System.Data.DbType.Int32, this.RedirectId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_Redirects SET "); updateQuery.Append("StoreId = @StoreId"); updateQuery.Append(", SourceUrl = @SourceUrl"); updateQuery.Append(", LoweredSourceUrl = @LoweredSourceUrl"); updateQuery.Append(", TargetUrl = @TargetUrl"); updateQuery.Append(", UseRegEx = @UseRegEx"); updateQuery.Append(", CreatedDate = @CreatedDate"); updateQuery.Append(", LastVisitedDate = @LastVisitedDate"); updateQuery.Append(", VisitCount = @VisitCount"); updateQuery.Append(", OrderBy = @OrderBy"); updateQuery.Append(" WHERE RedirectId = @RedirectId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@RedirectId", System.Data.DbType.Int32, this.RedirectId); database.AddInParameter(updateCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId); database.AddInParameter(updateCommand, "@SourceUrl", System.Data.DbType.String, this.SourceUrl); database.AddInParameter(updateCommand, "@LoweredSourceUrl", System.Data.DbType.String, this.LoweredSourceUrl); database.AddInParameter(updateCommand, "@TargetUrl", System.Data.DbType.String, this.TargetUrl); database.AddInParameter(updateCommand, "@UseRegEx", System.Data.DbType.Boolean, this.UseRegEx); database.AddInParameter(updateCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate)); database.AddInParameter(updateCommand, "@LastVisitedDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastVisitedDate))); database.AddInParameter(updateCommand, "@VisitCount", System.Data.DbType.Int32, NullableData.DbNullify(this.VisitCount)); 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_Redirects (StoreId, SourceUrl, LoweredSourceUrl, TargetUrl, UseRegEx, CreatedDate, LastVisitedDate, VisitCount, OrderBy)"); insertQuery.Append(" VALUES (@StoreId, @SourceUrl, @LoweredSourceUrl, @TargetUrl, @UseRegEx, @CreatedDate, @LastVisitedDate, @VisitCount, @OrderBy)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@RedirectId", System.Data.DbType.Int32, this.RedirectId); database.AddInParameter(insertCommand, "@StoreId", System.Data.DbType.Int32, this.StoreId); database.AddInParameter(insertCommand, "@SourceUrl", System.Data.DbType.String, this.SourceUrl); database.AddInParameter(insertCommand, "@LoweredSourceUrl", System.Data.DbType.String, this.LoweredSourceUrl); database.AddInParameter(insertCommand, "@TargetUrl", System.Data.DbType.String, this.TargetUrl); database.AddInParameter(insertCommand, "@UseRegEx", System.Data.DbType.Boolean, this.UseRegEx); database.AddInParameter(insertCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate)); database.AddInParameter(insertCommand, "@LastVisitedDate", System.Data.DbType.DateTime, NullableData.DbNullify(LocaleHelper.FromLocalTime(this.LastVisitedDate))); database.AddInParameter(insertCommand, "@VisitCount", System.Data.DbType.Int32, NullableData.DbNullify(this.VisitCount)); database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy); //RESULT IS NEW IDENTITY; result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand)); this._RedirectId = 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); }
/// <summary> /// Saves this WishlistItem 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.WishlistItemId == 0) { recordExists = false; } //SET DEFAULT FOR DATE FIELD if (this.CreatedDate == System.DateTime.MinValue) { this.CreatedDate = LocaleHelper.LocalNow; } if (this.LastModifiedDate == System.DateTime.MinValue) { this.LastModifiedDate = LocaleHelper.LocalNow; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_WishlistItems"); selectQuery.Append(" WHERE WishlistItemId = @WishlistItemId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@WishlistItemId", System.Data.DbType.Int32, this.WishlistItemId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_WishlistItems SET "); updateQuery.Append("WishlistId = @WishlistId"); updateQuery.Append(", ProductId = @ProductId"); updateQuery.Append(", OptionList = @OptionList"); updateQuery.Append(", KitList = @KitList"); updateQuery.Append(", Price = @Price"); updateQuery.Append(", LineMessage = @LineMessage"); updateQuery.Append(", CreatedDate = @CreatedDate"); updateQuery.Append(", LastModifiedDate = @LastModifiedDate"); updateQuery.Append(", Desired = @Desired"); updateQuery.Append(", Received = @Received"); updateQuery.Append(", Priority = @Priority"); updateQuery.Append(", Comment = @Comment"); updateQuery.Append(" WHERE WishlistItemId = @WishlistItemId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@WishlistItemId", System.Data.DbType.Int32, this.WishlistItemId); database.AddInParameter(updateCommand, "@WishlistId", System.Data.DbType.Int32, this.WishlistId); 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, "@KitList", System.Data.DbType.String, NullableData.DbNullify(this.KitList)); database.AddInParameter(updateCommand, "@Price", System.Data.DbType.Decimal, NullableData.DbNullify(this.Price)); database.AddInParameter(updateCommand, "@LineMessage", System.Data.DbType.String, NullableData.DbNullify(this.LineMessage)); database.AddInParameter(updateCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate)); database.AddInParameter(updateCommand, "@LastModifiedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.LastModifiedDate)); database.AddInParameter(updateCommand, "@Desired", System.Data.DbType.Int16, this.Desired); database.AddInParameter(updateCommand, "@Received", System.Data.DbType.Int16, this.Received); database.AddInParameter(updateCommand, "@Priority", System.Data.DbType.Byte, this.Priority); 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_WishlistItems (WishlistId, ProductId, OptionList, KitList, Price, LineMessage, CreatedDate, LastModifiedDate, Desired, Received, Priority, Comment)"); insertQuery.Append(" VALUES (@WishlistId, @ProductId, @OptionList, @KitList, @Price, @LineMessage, @CreatedDate, @LastModifiedDate, @Desired, @Received, @Priority, @Comment)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@WishlistItemId", System.Data.DbType.Int32, this.WishlistItemId); database.AddInParameter(insertCommand, "@WishlistId", System.Data.DbType.Int32, this.WishlistId); 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, "@KitList", System.Data.DbType.String, NullableData.DbNullify(this.KitList)); database.AddInParameter(insertCommand, "@Price", System.Data.DbType.Decimal, NullableData.DbNullify(this.Price)); database.AddInParameter(insertCommand, "@LineMessage", System.Data.DbType.String, NullableData.DbNullify(this.LineMessage)); database.AddInParameter(insertCommand, "@CreatedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.CreatedDate)); database.AddInParameter(insertCommand, "@LastModifiedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.LastModifiedDate)); database.AddInParameter(insertCommand, "@Desired", System.Data.DbType.Int16, this.Desired); database.AddInParameter(insertCommand, "@Received", System.Data.DbType.Int16, this.Received); database.AddInParameter(insertCommand, "@Priority", System.Data.DbType.Byte, this.Priority); database.AddInParameter(insertCommand, "@Comment", System.Data.DbType.String, NullableData.DbNullify(this.Comment)); //RESULT IS NEW IDENTITY; result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand)); this._WishlistItemId = 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 BasketItem 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.BasketItemId == 0) { recordExists = false; } if (this.OrderBy < 0) { this.OrderBy = BasketItemDataSource.GetNextOrderBy(this.BasketId); } //SET DEFAULT FOR DATE FIELD if (this.LastModifiedDate == System.DateTime.MinValue) { this.LastModifiedDate = LocaleHelper.LocalNow; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_BasketItems"); selectQuery.Append(" WHERE BasketItemId = @BasketItemId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@BasketItemId", System.Data.DbType.Int32, this.BasketItemId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_BasketItems SET "); updateQuery.Append("ParentItemId = @ParentItemId"); updateQuery.Append(", BasketId = @BasketId"); updateQuery.Append(", BasketShipmentId = @BasketShipmentId"); updateQuery.Append(", ProductId = @ProductId"); updateQuery.Append(", OptionList = @OptionList"); updateQuery.Append(", TaxCodeId = @TaxCodeId"); updateQuery.Append(", Name = @Name"); updateQuery.Append(", Sku = @Sku"); updateQuery.Append(", Price = @Price"); updateQuery.Append(", Weight = @Weight"); updateQuery.Append(", Quantity = @Quantity"); updateQuery.Append(", LineMessage = @LineMessage"); updateQuery.Append(", OrderItemTypeId = @OrderItemTypeId"); updateQuery.Append(", OrderBy = @OrderBy"); updateQuery.Append(", WrapStyleId = @WrapStyleId"); updateQuery.Append(", GiftMessage = @GiftMessage"); updateQuery.Append(", WishlistItemId = @WishlistItemId"); updateQuery.Append(", ShippableId = @ShippableId"); updateQuery.Append(", LastModifiedDate = @LastModifiedDate"); updateQuery.Append(", TaxRate = @TaxRate"); updateQuery.Append(", TaxAmount = @TaxAmount"); updateQuery.Append(", KitList = @KitList"); updateQuery.Append(", CustomFields = @CustomFields"); updateQuery.Append(" WHERE BasketItemId = @BasketItemId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@BasketItemId", System.Data.DbType.Int32, this.BasketItemId); database.AddInParameter(updateCommand, "@ParentItemId", System.Data.DbType.Int32, this.ParentItemId); database.AddInParameter(updateCommand, "@BasketId", System.Data.DbType.Int32, this.BasketId); database.AddInParameter(updateCommand, "@BasketShipmentId", System.Data.DbType.Int32, NullableData.DbNullify(this.BasketShipmentId)); 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, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId)); database.AddInParameter(updateCommand, "@Name", System.Data.DbType.String, this.Name); 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, "@Quantity", System.Data.DbType.Int16, this.Quantity); database.AddInParameter(updateCommand, "@LineMessage", System.Data.DbType.String, NullableData.DbNullify(this.LineMessage)); database.AddInParameter(updateCommand, "@OrderItemTypeId", System.Data.DbType.Int16, this.OrderItemTypeId); database.AddInParameter(updateCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy); database.AddInParameter(updateCommand, "@WrapStyleId", System.Data.DbType.Int32, NullableData.DbNullify(this.WrapStyleId)); database.AddInParameter(updateCommand, "@GiftMessage", System.Data.DbType.String, NullableData.DbNullify(this.GiftMessage)); database.AddInParameter(updateCommand, "@WishlistItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.WishlistItemId)); database.AddInParameter(updateCommand, "@ShippableId", System.Data.DbType.Byte, this.ShippableId); database.AddInParameter(updateCommand, "@LastModifiedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.LastModifiedDate)); 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_BasketItems (ParentItemId, BasketId, BasketShipmentId, ProductId, OptionList, TaxCodeId, Name, Sku, Price, Weight, Quantity, LineMessage, OrderItemTypeId, OrderBy, WrapStyleId, GiftMessage, WishlistItemId, ShippableId, LastModifiedDate, TaxRate, TaxAmount, KitList, CustomFields)"); insertQuery.Append(" VALUES (@ParentItemId, @BasketId, @BasketShipmentId, @ProductId, @OptionList, @TaxCodeId, @Name, @Sku, @Price, @Weight, @Quantity, @LineMessage, @OrderItemTypeId, @OrderBy, @WrapStyleId, @GiftMessage, @WishlistItemId, @ShippableId, @LastModifiedDate, @TaxRate, @TaxAmount, @KitList, @CustomFields)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@BasketItemId", System.Data.DbType.Int32, this.BasketItemId); database.AddInParameter(insertCommand, "@ParentItemId", System.Data.DbType.Int32, this.ParentItemId); database.AddInParameter(insertCommand, "@BasketId", System.Data.DbType.Int32, this.BasketId); database.AddInParameter(insertCommand, "@BasketShipmentId", System.Data.DbType.Int32, NullableData.DbNullify(this.BasketShipmentId)); 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, "@TaxCodeId", System.Data.DbType.Int32, NullableData.DbNullify(this.TaxCodeId)); database.AddInParameter(insertCommand, "@Name", System.Data.DbType.String, this.Name); 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, "@Quantity", System.Data.DbType.Int16, this.Quantity); database.AddInParameter(insertCommand, "@LineMessage", System.Data.DbType.String, NullableData.DbNullify(this.LineMessage)); database.AddInParameter(insertCommand, "@OrderItemTypeId", System.Data.DbType.Int16, this.OrderItemTypeId); database.AddInParameter(insertCommand, "@OrderBy", System.Data.DbType.Int16, this.OrderBy); database.AddInParameter(insertCommand, "@WrapStyleId", System.Data.DbType.Int32, NullableData.DbNullify(this.WrapStyleId)); database.AddInParameter(insertCommand, "@GiftMessage", System.Data.DbType.String, NullableData.DbNullify(this.GiftMessage)); database.AddInParameter(insertCommand, "@WishlistItemId", System.Data.DbType.Int32, NullableData.DbNullify(this.WishlistItemId)); database.AddInParameter(insertCommand, "@ShippableId", System.Data.DbType.Byte, this.ShippableId); database.AddInParameter(insertCommand, "@LastModifiedDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.LastModifiedDate)); 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._BasketItemId = 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 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); }
/// <summary> /// Loads a collection of orders associated to a given affiliate /// </summary> /// <param name="affiliateId">Affiliate for which to load the orders</param> /// <param name="startDate">start date to consider when loading orders</param> /// <param name="endDate">end date to consider when loading orders</param> /// <param name="sortExpression">Sort expression to use for sorting the loaded objects</param> /// <returns>A collection of orders associated to a given affiliate</returns> public static OrderCollection LoadForAffiliate(int affiliateId, DateTime startDate, DateTime endDate, string sortExpression) { StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT "); selectQuery.Append(Order.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_Orders"); selectQuery.Append(" WHERE AffiliateId = @affiliateId"); selectQuery.Append(" AND StoreId = @storeId"); if (startDate > DateTime.MinValue) { selectQuery.Append(" AND OrderDate >= @startDate"); } if (endDate > DateTime.MinValue) { selectQuery.Append(" AND OrderDate <= @endDate"); } if (!string.IsNullOrEmpty(sortExpression)) { selectQuery.Append(" ORDER BY " + sortExpression); } Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@affiliateId", System.Data.DbType.Int32, affiliateId); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); if (startDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(startDate)); } if (endDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(endDate)); } OrderCollection results = new OrderCollection(); using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { Order order = new Order(); Order.LoadDataReader(order, dr); results.Add(order); } dr.Close(); } return(results); }
/// <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); }
/// <summary> /// Loads a collection of orders associated to the given coupon code /// </summary> /// <param name="couponCode">Coupon Code for which to load the associated orders</param> /// <param name="startDate">start date to consider when loading orders</param> /// <param name="endDate">end date to consider when loading orders</param> /// <param name="sortExpression">Sort expression to use for sorting the loaded objects</param> /// <returns>A collection of orders associated to the given coupon code</returns> public static OrderCollection LoadForCouponCode(string couponCode, DateTime startDate, DateTime endDate, string sortExpression) { StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT "); selectQuery.Append(Order.GetColumnNames("O")); selectQuery.Append(" FROM ac_Orders O INNER JOIN ac_OrderCoupons C ON O.OrderId = C.OrderId"); selectQuery.Append(" WHERE C.CouponCode = @couponCode"); selectQuery.Append(" AND O.StoreId = @storeId"); List <OrderStatus> reportStatuses = OrderStatusDataSource.GetReportStatuses(); selectQuery.Append(" AND " + ReportDataSource.GetStatusFilter(reportStatuses, "O")); if (startDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate >= @startDate"); } if (endDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate <= @endDate"); } if (!string.IsNullOrEmpty(sortExpression)) { selectQuery.Append(" ORDER BY " + sortExpression); } Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@couponCode", System.Data.DbType.String, couponCode); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); if (startDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(startDate)); } if (endDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(endDate)); } ReportDataSource.SetStatusFilterParams(reportStatuses, database, selectCommand); OrderCollection results = new OrderCollection(); using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { Order order = new Order(); Order.LoadDataReader(order, dr); results.Add(order); } dr.Close(); } return(results); }
/// <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); }
/// <summary> /// Gets coupons codes used for orders /// </summary> /// <param name="startDate">The starting date for orders to be checked for coupons</param> /// <param name="endDate">The ending date for orders to be checked for coupons</param> /// <returns>An array of string with the codes of coupons used</returns> public static string[] GetCouponCodes(DateTime startDate, DateTime endDate) { StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT DISTINCT(C.CouponCode)"); selectQuery.Append(" FROM ac_Orders O INNER JOIN ac_OrderCoupons C ON O.OrderId = C.OrderId"); selectQuery.Append(" WHERE O.StoreId = @storeId"); if (startDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate >= @startDate"); } if (endDate > DateTime.MinValue) { selectQuery.Append(" AND O.OrderDate <= @endDate"); } List <OrderStatus> reportStatuses = OrderStatusDataSource.GetReportStatuses(); selectQuery.Append(" AND " + ReportDataSource.GetStatusFilter(reportStatuses, "O")); selectQuery.Append(" ORDER BY C.CouponCode"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); if (startDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(startDate)); } if (endDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(endDate)); } ReportDataSource.SetStatusFilterParams(reportStatuses, database, selectCommand); List <string> results = new List <string>(); using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { results.Add(dr.GetString(0)); } dr.Close(); } if (results.Count == 0) { return(null); } return(results.ToArray()); }
/// <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); }
public static OrderItemCollection LoadForOrderItemType(OrderItemType orderItemType, DateTime startDate, DateTime endDate, int maximumRows, int startRowIndex) { //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(" " + OrderItem.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_OrderItems"); selectQuery.Append(" WHERE OrderItemTypeId = @orderItemType"); selectQuery.Append(" AND OrderId IN ( SELECT OrderId From ac_Orders WHERE StoreId = @storeId"); if (startDate > DateTime.MinValue) { //CONVERT DATE TO UTC startDate = LocaleHelper.FromLocalTime(startDate); selectQuery.Append(" AND OrderDate >= @startDate"); } if (endDate > DateTime.MinValue) { //CONVERT DATE TO UTC endDate = LocaleHelper.FromLocalTime(endDate); selectQuery.Append(" AND OrderDate <= @endDate"); } selectQuery.Append(")"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@orderItemType", System.Data.DbType.Int32, orderItemType); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); if (startDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, startDate); } if (endDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, endDate); } //EXECUTE THE COMMAND OrderItemCollection results = new OrderItemCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { OrderItem orderItem = new OrderItem(); OrderItem.LoadDataReader(orderItem, dr); results.Add(orderItem); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
/// <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); }
/// <summary> /// Saves this ProductReview 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.ProductReviewId == 0) { recordExists = false; } //SET DEFAULT FOR DATE FIELD if (this.ReviewDate == System.DateTime.MinValue) { this.ReviewDate = LocaleHelper.LocalNow; } if (recordExists) { //verify whether record is already present StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT COUNT(*) As RecordCount FROM ac_ProductReviews"); selectQuery.Append(" WHERE ProductReviewId = @ProductReviewId"); using (DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString())) { database.AddInParameter(selectCommand, "@ProductReviewId", System.Data.DbType.Int32, this.ProductReviewId); if ((int)database.ExecuteScalar(selectCommand) == 0) { recordExists = false; } } } int result = 0; if (recordExists) { //UPDATE StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE ac_ProductReviews SET "); updateQuery.Append("ProductId = @ProductId"); updateQuery.Append(", ReviewerProfileId = @ReviewerProfileId"); updateQuery.Append(", ReviewDate = @ReviewDate"); updateQuery.Append(", Rating = @Rating"); updateQuery.Append(", ReviewTitle = @ReviewTitle"); updateQuery.Append(", ReviewBody = @ReviewBody"); updateQuery.Append(", IsApproved = @IsApproved"); updateQuery.Append(" WHERE ProductReviewId = @ProductReviewId"); using (DbCommand updateCommand = database.GetSqlStringCommand(updateQuery.ToString())) { database.AddInParameter(updateCommand, "@ProductReviewId", System.Data.DbType.Int32, this.ProductReviewId); database.AddInParameter(updateCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId); database.AddInParameter(updateCommand, "@ReviewerProfileId", System.Data.DbType.Int32, this.ReviewerProfileId); database.AddInParameter(updateCommand, "@ReviewDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.ReviewDate)); database.AddInParameter(updateCommand, "@Rating", System.Data.DbType.Byte, this.Rating); database.AddInParameter(updateCommand, "@ReviewTitle", System.Data.DbType.String, this.ReviewTitle); database.AddInParameter(updateCommand, "@ReviewBody", System.Data.DbType.String, this.ReviewBody); database.AddInParameter(updateCommand, "@IsApproved", System.Data.DbType.Boolean, this.IsApproved); //RESULT IS NUMBER OF RECORDS AFFECTED result = database.ExecuteNonQuery(updateCommand); } } else { //INSERT StringBuilder insertQuery = new StringBuilder(); insertQuery.Append("INSERT INTO ac_ProductReviews (ProductId, ReviewerProfileId, ReviewDate, Rating, ReviewTitle, ReviewBody, IsApproved)"); insertQuery.Append(" VALUES (@ProductId, @ReviewerProfileId, @ReviewDate, @Rating, @ReviewTitle, @ReviewBody, @IsApproved)"); insertQuery.Append("; SELECT Scope_Identity()"); using (DbCommand insertCommand = database.GetSqlStringCommand(insertQuery.ToString())) { database.AddInParameter(insertCommand, "@ProductReviewId", System.Data.DbType.Int32, this.ProductReviewId); database.AddInParameter(insertCommand, "@ProductId", System.Data.DbType.Int32, this.ProductId); database.AddInParameter(insertCommand, "@ReviewerProfileId", System.Data.DbType.Int32, this.ReviewerProfileId); database.AddInParameter(insertCommand, "@ReviewDate", System.Data.DbType.DateTime, LocaleHelper.FromLocalTime(this.ReviewDate)); database.AddInParameter(insertCommand, "@Rating", System.Data.DbType.Byte, this.Rating); database.AddInParameter(insertCommand, "@ReviewTitle", System.Data.DbType.String, this.ReviewTitle); database.AddInParameter(insertCommand, "@ReviewBody", System.Data.DbType.String, this.ReviewBody); database.AddInParameter(insertCommand, "@IsApproved", System.Data.DbType.Boolean, this.IsApproved); //RESULT IS NEW IDENTITY; result = AlwaysConvert.ToInt(database.ExecuteScalar(insertCommand)); this._ProductReviewId = 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); }