private async Task <bool> CheckZipcodeAsync(string zip, GetShippingOptionResponse response) { if (zip.Length < 5) { response.AddError("Zip code must be at least 5 digits."); return(false); } var firstFive = zip.Substring(0, 5); int zipNum; if (int.TryParse(firstFive, out zipNum)) { var isZipEligible = await _deliveryService.CheckZipcodeAsync(zipNum); if (isZipEligible) { return(true); } else { response.AddError("Home Delivery Shipping is not available for the given zip code."); } } else { response.AddError("Invalid Zipcode"); } return(false); }
public async Task <IActionResult> GetDeliveryOptions(int?productId, int?zip) { if (zip == null || zip.ToString().Length != 5) { return(BadRequest("Zip code must be a 5 digit number provided as a query parameter 'zip'.")); } return(Json(new { isDeliveryAvailable = await _deliveryService.CheckZipcodeAsync(zip.Value) })); }