コード例 #1
0
        public async Task <HttpResponseMessage> GetClaimInfo([FromUri] UpdateChargeRequest request)
        {
            logInfo.Info(string.Format("【收费服务】获取车辆出险信息接口请求串:{0}", Request.RequestUri));
            CarClaimViewModel viewModel = new CarClaimViewModel();

            if (!ModelState.IsValid)
            {
                viewModel.BusinessStatus = -10000;
                string msg = ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + ";   "));
                viewModel.StatusMessage = "输入参数错误," + msg;
                return(viewModel.ResponseToJson());
            }
            if (!request.LicenseNo.IsValidLicenseno())
            {
                viewModel.BusinessStatus = -10000;
                viewModel.StatusMessage  = "参数校验错误,请检查车牌号";
                return(viewModel.ResponseToJson());
            }
            try
            {
                var response = await _chargeService.UpdateClaim(request, Request.GetQueryNameValuePairs());

                if (response.Status == HttpStatusCode.BadRequest || response.Status == HttpStatusCode.Forbidden)
                {
                    viewModel.BusinessStatus = -10001;
                    viewModel.StatusMessage  = "参数校验错误,请检查您的校验码";
                    return(viewModel.ResponseToJson());
                }
                if (response.Status == HttpStatusCode.ExpectationFailed)
                {
                    viewModel.BusinessStatus = -10003;
                    viewModel.StatusMessage  = "服务发生异常";
                }
                else
                {
                    if (response.ErrCode == 0)
                    {
                        viewModel                = response.List.ConvertToViewModel();
                        viewModel.LicenseNo      = request.LicenseNo;
                        viewModel.TotalCount     = response.TotalCount;
                        viewModel.UsedCount      = response.UsedCount;
                        viewModel.BusinessStatus = 1;
                    }
                    else if (response.ErrCode == -2)
                    {
                        viewModel.BusinessStatus = 2;//余额不足
                    }
                    else if (response.ErrCode == -1)
                    {
                        viewModel.BusinessStatus = 3;//没有获取到
                    }
                }
            }
            catch (Exception ex)
            {
                logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }

            return(viewModel.ResponseToJson());
        }
コード例 #2
0
ファイル: SiteExamples.cs プロジェクト: SallyAbbas/Testms
        public async Task ChargesUpdateUpdateDescription()
        {
            var request = new UpdateChargeRequest {
                Description = "Updated Description",
            };

            var charge = await Client.Charges.Update("chrg_test_52ydurgt5nhckrxbvxh", request);

            Assert.AreEqual(request.Description, charge.Description);
        }
コード例 #3
0
        public async Task <UpdateChargeResponse> Update(UpdateChargeRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var response = new UpdateChargeResponse();

            //根据经纪人获取手机号
            IBxAgent agentModel = GetAgentModelFactory(request.Agent);

            //logInfo.Info("获取到的经纪人信息:"+agentModel.ToJson());
            //参数校验
            if (!agentModel.AgentCanUse())
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }

            if (!ValidateReqest(pairs, agentModel.SecretKey, request.SecCode))
            {
                response.Status = HttpStatusCode.Forbidden;
                return(response);
            }

            bx_charge charge = _chargeRepository.Find(request.Agent, request.BusyKey);

            if (charge == null)
            {
                response.Status = HttpStatusCode.BadRequest;
                return(response);
            }
            try
            {
                //发送请求 checkneed
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(_url);
                    var requestmodel = new
                    {
                        LicenseNo = request.LicenseNo,
                        Agent     = request.Agent
                    };

                    HttpResponseMessage res = await client.PostAsJsonAsync("api/userinfo/FindCarInfoBy", requestmodel);

                    if (res.IsSuccessStatusCode)
                    {
                        WaFindCarInfoResponse result = await res.Content.ReadAsAsync <WaFindCarInfoResponse>();

                        if (result.ErrCode == 0)
                        {
                            //更新bx_charge

                            if (charge.total_count == charge.used_count)
                            {
                                //余额不足
                                response.Status  = HttpStatusCode.OK;
                                response.ErrCode = -2;
                                return(response);
                            }

                            charge.used_count += 1;
                            charge.update_time = DateTime.Now;
                            var chargeCount = _chargeRepository.Update(charge);
                            if (chargeCount == 1)
                            {
                                //插入bx_charge_history
                                var history = new bx_charge_history
                                {
                                    charge_id     = charge.id,
                                    license_no    = request.LicenseNo,
                                    result_status = 1 //成功
                                };
                                _chargeHistoryRepository.Add(history);
                            }

                            response.TotalCount   = charge.total_count.HasValue ? charge.total_count.Value : 0;
                            response.UsedCount    = charge.used_count.HasValue ? charge.used_count.Value : 0;
                            response.MoldName     = result.CarInfo.MoldName;
                            response.CarVin       = result.CarInfo.CarVin;
                            response.RegisterDate = result.CarInfo.RegisteDate;
                            response.LicenseNo    = result.CarInfo.PlateNo;
                            response.EngineNo     = result.CarInfo.EngineNo;
                            response.LicenseOwner = result.CarInfo.LicenseOwner;
                            response.OwnerIdNo    = result.CarInfo.OwnerIdNo;
                            response.Status       = HttpStatusCode.OK;
                            response.ErrCode      = 0;
                            return(response);
                        }
                        else
                        {
                            //插入bx_charge_history
                            var history = new bx_charge_history
                            {
                                charge_id     = charge.id,
                                license_no    = request.LicenseNo,
                                result_status = 0 //失败
                            };
                            _chargeHistoryRepository.Add(history);
                            response.Status  = HttpStatusCode.OK;
                            response.ErrCode = -1;
                            return(response);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.Status = HttpStatusCode.ExpectationFailed;
                logError.Info("收费服务-获取车辆信息发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }

            return(response);
        }