Beispiel #1
0
        public HttpResponseMessage GetAgentIdentity([FromUri] GetAgentIdentityAndRateRequest request)
        {
            _logInfo.Info(string.Format("获取代理人身份接口请求串:{0}", Request.RequestUri));
            var viewModel = new AgentIdentityAndRateViewModel();

            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());
            }
            var response = _agentService.GetAgent(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
            {
                viewModel = response.ConvertToViewModel();
                viewModel.BusinessStatus = 1;
            }
            return(viewModel.ResponseToJson());
        }
        public static AgentIdentityAndRateViewModel ConvertToViewModel(this GetAgentIdentityAndRateResponse response)
        {
            var model = new AgentIdentityAndRateViewModel();

            //model.Item = new AgentIdentityAndRateViewModel.AgentIdentityAndRate
            //{
            //    BizRate = response.BizRate,
            //    ForceRate = response.ForceRate,
            //    IsAgent = response.IsAgent,
            //    TaxRate = response.TaxRate
            //};
            model.Item         = new AgentIdentityAndRateViewModel.AgentIdentityAndRate();
            model.Item.IsAgent = response.IsAgent;
            if (response.IsAgent == 1)
            {
                if (response.AgentRate != null)
                {
                    model.Item.AgentRate = new AgentIdentityAndRateViewModel.Rate
                    {
                        BizRate   = response.AgentRate.BizRate,
                        ForceRate = response.AgentRate.ForceRate,
                        TaxRate   = response.AgentRate.TaxRate
                    };
                }
                else
                {
                    model.Item.AgentRate = new AgentIdentityAndRateViewModel.Rate();
                }

                model.Item.ZhiKeRate = new List <AgentIdentityAndRateViewModel.Rate>();
            }
            else
            {
                model.Item.AgentRate = new AgentIdentityAndRateViewModel.Rate();
                model.Item.ZhiKeRate = new List <AgentIdentityAndRateViewModel.Rate>();
                if (response.ZhiKeRate != null)
                {
                    for (int i = 0; i < response.ZhiKeRate.Count; i++)
                    {
                        model.Item.ZhiKeRate.Add(new AgentIdentityAndRateViewModel.Rate
                        {
                            BizRate = response.ZhiKeRate[i].BizRate,
                            Source  = response.ZhiKeRate[i].Source
                        });
                    }
                }
                else
                {
                    model.Item.ZhiKeRate = new List <AgentIdentityAndRateViewModel.Rate>();
                }
            }
            return(model);
        }