예제 #1
0
        private VerificationRequest BuildRequest(string accountCode, string auditCode, string leadId, IEnumerable<FieldInfo> leadFields)
        {
            var request = new VerificationRequest
            {
                Lac = accountCode,
                Vid = auditCode,
                UniversalLeadIDToken = leadId
            };
            var requestType = request.GetType();

            _fslpMapper.Get().ToList().ForEach(x =>
            {
                var field = leadFields.FirstOrDefault(lf => lf.Name == x.SourceColumn);
                if (field == null)
                {
                    throw new InvalidOperationException(string.Format("Required field '{0}' for the verification process was not present at the request", x));
                }

                var prop = requestType.GetProperty(x.SourceColumn);
                if (prop == null)
                {
                    throw new InvalidOperationException(string.Format("Required field '{0}' for the verification process was not present at the request data type on the service", x));
                }

                prop.SetValue(request, field.Value, null);
            });

            return request;
        }
예제 #2
0
        private string BuildRequest(VerificationRequest request)
        {
            var allFields = from x in request.GetType().GetProperties()
                            join y in _requestMapper.Get() on x.Name.ToLower() equals y.SourceColumn.ToLower()
                            select string.Format(DataMappingFormat, y.TargetColumn, x.GetValue(request));
            var builder = new StringBuilder();

            allFields.ToList().ForEach(x => builder.Append(x));

            return string.Format(ServiceUrl, request.Lac, request.UniversalLeadIDToken, request.Vid, request.Lpc, builder.Remove(builder.Length - 1, 1).ToString());
        }
예제 #3
0
        /// <summary>
        /// Should be invoked by 3rd party role 
        /// </summary>
        public async Task<ActionResult> VerifyLeadAsync(VerificationRequest request)
        {
            var response = await Task.Run<VerificationResponse>(() =>
            {
                var client = new LeadIdServiceAgent(_requestMapper, _responseMapper);
                return client.VerifyLeadAsync(request);
            });

            return new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.DenyGet,
                Data = response.JsonCamelCase()
            };
        }
예제 #4
0
        public async Task<VerificationResponse> VerifyLeadAsync(VerificationRequest request)
        {
            var response = new VerificationResponse();

            try
            {
                response.RequestString = BuildRequest(request);

                using (var client = new WebClient())
                {
                    response.ResponseString = await client.DownloadStringTaskAsync(response.RequestString);
                    var results = JObject.Parse(response.ResponseString);

                    _responseMapper
                        .Get()
                        .ToList()
                        .ForEach(x =>
                        {
                            var value = results["audit"].ExtractValue(x.SourceColumn);

                            if (value != null)
                            {
                                response.Fields.Add(new ResponseField { Name = x.TargetColumn, Value = value });
                            }
                        });
                    response.Success = true;
                }
            }
            catch (Exception e)
            {
                response.Success = false;
                response.ResponseString += string.Format(" Errors: {0}", e.Message);
            }

            return response;
        }