示例#1
0
        /// <summary>
        ///  新增 一分钱洗车优惠券领取记录
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static async Task <int> CreateWashCarCouponAsync(WashCarCouponRecordEntity entity)
        {
            #region sql
            var sql = @" insert into  Activity.[dbo].[WashCarCouponRecord]
                         (  
                            UserID
                           ,PromotionCodeID
                           ,CarID
                           ,CarNo
                           ,VehicleID
                           ,Vehicle
                           ,PaiLiang
                           ,Nian
                           ,Tid
                           ,CreateDateTime
                           ,LastUpdateDateTime
                         )
                         values (
                            @UserID
                           ,@PromotionCodeID
                           ,@CarID
                           ,@CarNo
                           ,@VehicleID
                           ,@Vehicle
                           ,@PaiLiang
                           ,@Nian
                           ,@Tid
                           ,getdate()
                           ,getdate()
                         );
                        SELECT SCOPE_IDENTITY();
                          ";
            #endregion


            using (var cmd = new SqlCommand(sql))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@UserID", entity.UserID);
                cmd.Parameters.AddWithValue("@PromotionCodeID", entity.PromotionCodeID);
                cmd.Parameters.AddWithValue("@CarID", entity.CarID);
                cmd.Parameters.AddWithValue("@CarNo", entity.CarNo);
                cmd.Parameters.AddWithValue("@VehicleID", entity.VehicleID);
                cmd.Parameters.AddWithValue("@Vehicle", entity.Vehicle);
                cmd.Parameters.AddWithValue("@PaiLiang", entity.PaiLiang);
                cmd.Parameters.AddWithValue("@Nian", entity.Nian);
                cmd.Parameters.AddWithValue("@Tid", entity.Tid);
                return(Convert.ToInt32(await DbHelper.ExecuteScalarAsync(cmd)));
            }
        }
        /// <summary>
        ///  新增 一分钱洗车优惠券领取记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task <OperationResult <bool> > CreateWashCarCouponAsync(WashCarCouponRecordModel request)
        {
            try
            {
                #region 新增时 数据验证
                string validMSG = "";
                if (request == null)
                {
                    validMSG = "请求参数不能为空";
                }
                else if (string.IsNullOrWhiteSpace(request.CarNo))
                {
                    validMSG = "车牌号不能为空";
                }
                else if (Guid.Empty == request.UserID)
                {
                    validMSG = "用户不能为空";
                }
                else if (request.PromotionCodeID <= 0)
                {
                    validMSG = "优惠券不能为空";
                }
                if (!string.IsNullOrWhiteSpace(validMSG))
                {
                    return(OperationResult.FromError <bool>("-1", validMSG));
                }
                #endregion
                WashCarCouponRecordEntity entity = ObjectMapper.ConvertTo <WashCarCouponRecordModel, WashCarCouponRecordEntity>(request);
                var result = await DalWashCarCouponRecord.CreateWashCarCouponAsync(entity);

                return(OperationResult.FromResult(result > 0));
            }
            catch (Exception ex)
            {
                return(OperationResult.FromError <bool>("500", ex.Message));
            }
        }