コード例 #1
0
        /// <summary>
        /// 新增客户地址
        /// </summary>
        /// <param name="customerId">客户Id</param>
        /// <param name="linkname">联系人</param>
        /// <param name="mobile">手机号</param>
        /// <param name="address">地址</param>
        /// <param name="isDefault">是否默认</param>
        /// <param name="creator">创建人</param>
        public void Add(string customerId, string linkname, string mobile, string address, string isDefault, string creator)
        {
            using (DbConnection conn = DbHelper.CreateConnection())
            {
                DbTransaction trans = null;
                try
                {
                    conn.Open();
                    trans = conn.BeginTransaction();
                    if (trans == null)
                    {
                        throw new ArgumentNullException("DbTransaction");
                    }
                    CustomerAddress entity = new CustomerAddress();
                    entity.Create(customerId, address, mobile, linkname, isDefault, creator);
                    if (entity.IsDefaultAddress())
                    {
                        CustomerAddress defaultEntity = this.customerAddressRepository.GetDefaultAddres(trans, customerId);
                        if (defaultEntity != null)
                        {
                            defaultEntity.CancelDefault(creator);
                            this.customerAddressRepository.Update(trans, defaultEntity);
                        }
                    }
                    this.customerAddressRepository.Insert(trans, entity);

                    trans.Commit();
                }
                catch
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 设置默认客户地址
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="mender">修改人</param>
        public void SetDefault(string id, string mender)
        {
            using (DbConnection conn = DbHelper.CreateConnection())
            {
                DbTransaction trans = null;
                try
                {
                    conn.Open();
                    trans = conn.BeginTransaction();
                    if (trans == null)
                    {
                        throw new ArgumentNullException("DbTransaction");
                    }
                    CustomerAddress entity = this.Select(trans, id);
                    if (!entity.IsDefaultAddress())
                    {
                        CustomerAddress defaultEntity = this.customerAddressRepository.GetDefaultAddres(trans, entity.CustomerId);
                        if (defaultEntity != null)
                        {
                            defaultEntity.CancelDefault(mender);
                            this.customerAddressRepository.Update(trans, defaultEntity);
                        }
                        entity.SetDefault(mender);
                        this.customerAddressRepository.Update(trans, entity);

                        trans.Commit();
                    }
                }
                catch
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw;
                }
            }
        }