/// <summary> /// 添加满件优惠促销活动. /// </summary> /// <param name="promoteMeetAmount"> /// Promote_MeetAmount的对象. /// </param> /// <returns> /// 满件优惠的编号. /// </returns> public int Add(Promote_MeetAmount promoteMeetAmount) { SqlTransaction transaction = null; try { // 添加促销活动主信息 var meetAmountID = this.promoteMeetAmountDA.Insert(promoteMeetAmount, out transaction); promoteMeetAmount.MeetAmountScope.MeetAmountID = meetAmountID; // 添加促销活动活动商品信息 this.promoteMeetAmountScopeDA.Insert(promoteMeetAmount.MeetAmountScope, transaction); // 添加促销活动规则 foreach (var promoteMeetAmountRule in promoteMeetAmount.MeetAmountRules) { promoteMeetAmountRule.PromoteMeetAmountID = meetAmountID; this.promoteMeetAmountRuleDA.Insert(promoteMeetAmountRule, transaction); } transaction.Commit(); return meetAmountID; } catch (Exception exception) { if (transaction != null) { transaction.Rollback(); } throw new Exception(exception.Message, exception); } }
/// <summary> /// 添加满件优惠促销活动. /// </summary> /// <param name="promoteMeetAmount"> /// Promote_MeetAmount的对象. /// </param> /// <param name="transaction"> /// 数据事务. /// </param> /// <returns> /// 满件优惠的编号. /// </returns> public int Insert(Promote_MeetAmount promoteMeetAmount, out SqlTransaction transaction) { if (promoteMeetAmount == null) { throw new ArgumentNullException("promoteMeetAmount"); } this.SqlServer.BeginTransaction(); transaction = this.SqlServer.Transaction; var parameters = new List<SqlParameter> { this.SqlServer.CreateSqlParameter( "EmployeeID", SqlDbType.Int, promoteMeetAmount.EmployeeID, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "Name", SqlDbType.NVarChar, promoteMeetAmount.Name, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "IsNewUser", SqlDbType.Bit, promoteMeetAmount.IsNewUser, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "IsMobileValidate", SqlDbType.Bit, promoteMeetAmount.IsMobileValidate, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "IsUseCoupon", SqlDbType.Bit, promoteMeetAmount.IsUseCoupon, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "StartTime", SqlDbType.DateTime, promoteMeetAmount.StartTime, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "EndTime", SqlDbType.DateTime, promoteMeetAmount.EndTime, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "Status", SqlDbType.Int, promoteMeetAmount.Status, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "Description", SqlDbType.NVarChar, promoteMeetAmount.Description, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "ReferenceID", SqlDbType.Int, promoteMeetAmount.ID, ParameterDirection.Output) }; this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Promote_MeetAmount_Insert", parameters, transaction); return (int)parameters.Find(parameter => parameter.ParameterName == "ReferenceID").Value; }
/// <summary> /// 修改满件优惠促销活动. /// </summary> /// <param name="promoteMeetAmount"> /// Promote_MeetAmount的对象. /// </param> /// <param name="transaction"> /// 数据事务. /// </param> public void Update(Promote_MeetAmount promoteMeetAmount, out SqlTransaction transaction) { if (promoteMeetAmount == null) { throw new ArgumentNullException("promoteMeetAmount"); } this.SqlServer.BeginTransaction(IsolationLevel.ReadCommitted); transaction = this.SqlServer.Transaction; var parameters = new List<SqlParameter> { this.SqlServer.CreateSqlParameter( "ID", SqlDbType.Int, promoteMeetAmount.ID, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "EmployeeID", SqlDbType.Int, promoteMeetAmount.EmployeeID, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "Name", SqlDbType.NVarChar, promoteMeetAmount.Name, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "IsNewUser", SqlDbType.Bit, promoteMeetAmount.IsNewUser, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "IsMobileValidate", SqlDbType.Bit, promoteMeetAmount.IsMobileValidate, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "IsUseCoupon", SqlDbType.Bit, promoteMeetAmount.IsUseCoupon, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "StartTime", SqlDbType.DateTime, promoteMeetAmount.StartTime, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "EndTime", SqlDbType.DateTime, promoteMeetAmount.EndTime, ParameterDirection.Input), this.SqlServer.CreateSqlParameter( "Description", SqlDbType.NVarChar, promoteMeetAmount.Description, ParameterDirection.Input) }; this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Promote_MeetAmount_Update", parameters, transaction); }
/// <summary> /// 修改满件优惠促销活动. /// </summary> /// <param name="promoteMeetAmount"> /// Promote_MeetAmount的对象. /// </param> /// <param name="removeRuleIdArry"> /// 删除的规则编号集合. /// </param> public void Modify(Promote_MeetAmount promoteMeetAmount, string[] removeRuleIdArry) { SqlTransaction transaction = null; try { // 修改促销活动主信息 this.promoteMeetAmountDA.Update(promoteMeetAmount, out transaction); // 修改促销活动活动商品信息 this.promoteMeetAmountScopeDA.Update(promoteMeetAmount.MeetAmountScope, transaction); // 添加或修改促销活动规则 foreach (var promoteMeetAmountRule in promoteMeetAmount.MeetAmountRules) { if (promoteMeetAmountRule.ID > 0) { this.promoteMeetAmountRuleDA.Update(promoteMeetAmountRule, transaction); } else { this.promoteMeetAmountRuleDA.Insert(promoteMeetAmountRule, transaction); } } if (removeRuleIdArry != null) { foreach (var ruleId in removeRuleIdArry) { if (!string.IsNullOrEmpty(ruleId)) { this.promoteMeetAmountRuleDA.Delete(Convert.ToInt32(ruleId), transaction); } } // 删除无用的活动规则 } transaction.Commit(); } catch (Exception exception) { if (transaction != null) { transaction.Rollback(); } throw new Exception(exception.Message, exception); } }