/// <summary>
        /// 添加满就送促销活动.
        /// </summary>
        /// <param name="promoteMeetMoney">
        /// Promote_MeetMoney的对象实例.
        /// </param>
        /// <returns>
        /// 满就送促销活动的编号.
        /// </returns>
        public int Add(Promote_MeetMoney promoteMeetMoney)
        {
            SqlTransaction transaction = null;

            try
            {
                var meetMoneyID = this.promoteMeetMoneyDA.Insert(promoteMeetMoney, out transaction); // 添加满额优惠主信息

                promoteMeetMoney.MeetMoneyScope.MeetMoneyID = meetMoneyID;
                this.promoteMeetMoneyScopeDA.Insert(promoteMeetMoney.MeetMoneyScope, transaction);  // 添加满额优惠活动范围

                // 添加满额优惠规则
                foreach (var promoteMeetMoneyRule in promoteMeetMoney.MeetMoneyRules)
                {
                    promoteMeetMoneyRule.PromoteMeetMoneyID = meetMoneyID;
                    this.promoteMeetMoneyRuleDA.Insert(promoteMeetMoneyRule, transaction);
                }

                transaction.Commit();
                return meetMoneyID;
            }
            catch (Exception exception)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }

                throw new Exception(exception.Message, exception);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加满就送促销活动.
        /// </summary>
        /// <param name="promoteMeetMoney">
        /// Promote_MeetMoney的对象实例.
        /// </param>
        /// <param name="transaction">
        /// 数据库事务.
        /// </param>
        /// <returns>
        /// 满就送促销活动的编号.
        /// </returns>
        public int Insert(Promote_MeetMoney promoteMeetMoney, out SqlTransaction transaction)
        {
            if (promoteMeetMoney == null)
            {
                throw new ArgumentNullException("promoteMeetMoney");
            }

            this.SqlServer.BeginTransaction();
            transaction = this.SqlServer.Transaction;

            var parameters = new List<SqlParameter>
                                 {
                                     this.SqlServer.CreateSqlParameter(
                                         "EmployeeID",
                                         SqlDbType.Int,
                                         promoteMeetMoney.EmployeeID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Name",
                                         SqlDbType.NVarChar,
                                         promoteMeetMoney.Name,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "StartTime",
                                         SqlDbType.DateTime,
                                         promoteMeetMoney.StartTime,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "EndTime",
                                         SqlDbType.DateTime,
                                         promoteMeetMoney.EndTime,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "IsNewUser",
                                         SqlDbType.Bit,
                                         promoteMeetMoney.IsNewUser,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "IsMobileValidate",
                                         SqlDbType.Bit,
                                         promoteMeetMoney.IsMobileValidate,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "IsUseCoupon",
                                         SqlDbType.Bit,
                                         promoteMeetMoney.IsUseCoupon,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Status",
                                         SqlDbType.Int,
                                         promoteMeetMoney.Status,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Description",
                                         SqlDbType.NVarChar,
                                         promoteMeetMoney.Description,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "ReferenceID",
                                         SqlDbType.Int,
                                         promoteMeetMoney.ID,
                                         ParameterDirection.Output)
                                 };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Promote_MeetMoney_Insert", parameters, transaction);
            return (int)parameters.Find(parameter => parameter.ParameterName == "ReferenceID").Value;
        }
        /// <summary>
        /// 修改满就送促销活动.
        /// </summary>
        /// <param name="promoteMeetMoney">
        /// Promote_MeetMoney的对象实例.
        /// </param>
        /// <param name="removeRuleIdArry">
        /// The remove Rule Id Items.
        /// </param>
        public void Modify(Promote_MeetMoney promoteMeetMoney, string[] removeRuleIdArry)
        {
            SqlTransaction transaction = null;

            try
            {
                // 修改促销活动主信息
                this.promoteMeetMoneyDA.Update(promoteMeetMoney, out transaction);

                // 修改促销活动活动商品信息
                this.promoteMeetMoneyScopeDA.Update(promoteMeetMoney.MeetMoneyScope, transaction);

                foreach (var promoteMeetMoneyRule in promoteMeetMoney.MeetMoneyRules)
                {
                    if (promoteMeetMoneyRule.ID > 0)
                    {
                        this.promoteMeetMoneyRuleDA.Update(promoteMeetMoneyRule, transaction);
                    }
                    else
                    {
                        promoteMeetMoneyRule.PromoteMeetMoneyID = promoteMeetMoney.ID;
                        this.promoteMeetMoneyRuleDA.Insert(promoteMeetMoneyRule, transaction);
                    } // 有该规则就修改,没有就添加
                }

                if (removeRuleIdArry != null)
                {
                    foreach (var ruleId in removeRuleIdArry)
                    {
                        if (!string.IsNullOrEmpty(ruleId))
                        {
                            this.promoteMeetMoneyRuleDA.Delete(Convert.ToInt32(ruleId), transaction);
                        }
                    } // 删除无用的活动规则
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }

                throw new Exception(exception.Message, exception);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改满就送促销活动.
        /// </summary>
        /// <param name="promoteMeetMoney">
        /// Promote_MeetMoney的对象实例.
        /// </param>
        /// <param name="transaction">
        /// 数据库事务.
        /// </param>
        public void Update(Promote_MeetMoney promoteMeetMoney, out SqlTransaction transaction)
        {
            if (promoteMeetMoney == null)
            {
                throw new ArgumentNullException("promoteMeetMoney");
            }

            this.SqlServer.BeginTransaction(IsolationLevel.ReadCommitted);
            transaction = this.SqlServer.Transaction;
            var parameters = new List<SqlParameter>
                                 {
                                     this.SqlServer.CreateSqlParameter(
                                         "ID",
                                         SqlDbType.Int,
                                         promoteMeetMoney.ID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "EmployeeID",
                                         SqlDbType.Int,
                                         promoteMeetMoney.EmployeeID,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Name",
                                         SqlDbType.NVarChar,
                                         promoteMeetMoney.Name,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "IsNewUser",
                                         SqlDbType.Bit,
                                         promoteMeetMoney.IsNewUser,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "IsMobileValidate",
                                         SqlDbType.Bit,
                                         promoteMeetMoney.IsMobileValidate,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "IsUseCoupon",
                                         SqlDbType.Bit,
                                         promoteMeetMoney.IsUseCoupon,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "StartTime",
                                         SqlDbType.DateTime,
                                         promoteMeetMoney.StartTime,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "EndTime",
                                         SqlDbType.DateTime,
                                         promoteMeetMoney.EndTime,
                                         ParameterDirection.Input),
                                     this.SqlServer.CreateSqlParameter(
                                         "Description",
                                         SqlDbType.NVarChar,
                                         promoteMeetMoney.Description,
                                         ParameterDirection.Input)
                                 };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Promote_MeetMoney_Update", parameters, transaction);
        }