Example #1
0
        public ActionResult GetAddressByZipCode(string zipcode)
        {
            //int postalCode = 0;

            /* if (!Int32.TryParse(zipcode, out postalCode))
             * {
             *   // not int
             *   Response.StatusCode = (int)HttpStatusCode.BadRequest;
             *   return Json(new { Error = "Invalid" });
             * }
             */

            if (string.IsNullOrEmpty(zipcode))
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Json(new { Error = "Invalid" }));
            }

            using (var addressManager = new AddressManager())
            {
                var address = addressManager.FindAddress(zipcode);

                if (address == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(Json(new { Error = "Invalid" }));
                }

                return(Json(new { Blk = address.StreetNumber, Street = address.StreetName }));
            }
        }