Exemplo n.º 1
0
        public ActionResult <List <AddressReturn> > CheckManyAddresses([FromBody] List <AddressInfo> addresssList)
        {
            try
            {
                var addressProcessing = new AddressProcessing(Configuration["Smarty:userName"], Configuration["Smarty:password"]);
                var returnList        = new ConcurrentBag <AddressReturn>();
                Parallel.ForEach(addresssList, (address) =>
                {
                    var addAddress = new AddressReturn();
                    try
                    {
                        addAddress = addressProcessing.ProcessAddress(address);
                    }
                    catch (Exception e)
                    {
                        addAddress.ValidAddress = false;
                        addAddress.errorMessage = e.Message;
                    }
                    returnList.Add(addAddress);
                });

                return(StatusCode(200, returnList));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public AddressReturn ProcessAddress(AddressInfo address)
        {
            var client        = new ClientBuilder(_username, _pwd).BuildUsStreetApiClient();
            var returnAddress = new AddressReturn();
            var lookup        = new Lookup
            {
                Street  = address.Address1,
                Street2 = address.Address2,
                City    = address.City,
                State   = address.City,
                ZipCode = address.Zip
            };

            client.Send(lookup);

            var result = lookup.Result;

            //Return true if first returned address matches supplied address
            if (result.Count <= 0)
            {
                returnAddress.ValidAddress = false;
            }
            else
            {
                var rAddress = result.FirstOrDefault();
                returnAddress.Address1     = address.Address1;
                returnAddress.Address2     = address.Address2;
                returnAddress.City         = rAddress.Components.CityName;
                returnAddress.State        = rAddress.Components.State;
                returnAddress.Zip          = rAddress.Components.ZipCode;
                returnAddress.Zip4Code     = rAddress.Components.Plus4Code;
                returnAddress.CassCode     = rAddress.Metadata.CarrierRoute;
                returnAddress.ValidAddress = true;
            }

            return(returnAddress);
        }