public object DoAffiliateSubmitLead([FromBody] string jsonString) { try { // Deserialize json string to the general DTO LeadApiParams object var leadApiParams = JsonConvert.DeserializeObject <Dto.LeadApiParams>(jsonString); var ipAddress = HttpContext.Current.Request.OriginatingClientIpAddress(); // Map the DTO LeadApiParams object to the PostRequest object (used for SEM proxy service) var postRequest = CreatePostRequestFromApiParams(leadApiParams); postRequest.IpAddress = ipAddress; // Make async call to SEM proxy service for lead submission var postResponseTask = AffiliateProxyService.SubmitLeadAsync(postRequest); // Map the DTO LeadApiParams object to the Lead object (used for SQL inserts and local caching) var lead = CreateLeadFromApiParams(leadApiParams); // Set some server-side maintained flags and save the lead asynchronously // ...but we will not be waiting this time! LeadDataService .SetIpAddress(lead, ipAddress) .SaveAsync(lead); // Wait for SEM proxy service async call to finish postResponseTask.Wait(); // Map the lead submission response from the SEM proxy service to the DTO SubmitLeadResponse object var postResponse = postResponseTask.Result; var submitLeadResponse = CreateSubmitLeadResponseFromSemServiceResponse(postResponse); if (postResponse.IsSuccess) { LeadDataService .SetSuccessfulLeadSubmit(lead, true) .SaveAsync(lead); } return(submitLeadResponse); } catch (Exception ex) { return(new { isKosher = false }); } }