Пример #1
0
        public object DoAffiliatePlacementCheckLead([FromBody] string jsonString)
        {
            try
            {
                // Deserialize json string to the general DTO LeadApiParams object
                var leadApiParams = JsonConvert.DeserializeObject <Dto.LeadApiParams>(jsonString);


                // Map the DTO LeadApiParams object to the PingRequest object (used for SEM proxy service)
                var pingRequest = CreatePingRequestFromApiParams(leadApiParams);
                // Make async call to SEM proxy service for placement check
                var pingResponseTask = AffiliateProxyService.PlacementCheckAsync(pingRequest);


                // Map the DTO LeadApiParams object to the Lead object (used for SQL inserts and local caching)
                var leadToSave = CreateLeadFromApiParams(leadApiParams);
                // Make an async call to LeadDataService to save the lead to SQL
                var leadSaveTask = LeadDataService.SaveAsync(leadToSave);
                //var lead = LeadDataService.Save(leadToSave);


                // Wait for SEM proxy service async call to finish
                pingResponseTask.Wait();
                // Map the placement check response from the SEM proxy service to the DTO PlacementCheckResponse object
                var pingResponse           = pingResponseTask.Result;
                var placementCheckResponse = CreatePlacementCheckResponseFromSemServiceResponse(pingResponse);

                // Wait for Lead service async call to finish
                leadSaveTask.Wait();

                // Add the SQL record id to the placement check response
                var lead = leadSaveTask.Result;
                placementCheckResponse.Id = lead.Id;

                // Set the session id, set a server-side maintained flag, then save the lead asynchronously
                // ...but we will not be waiting this time!
                if (pingResponse.IsSuccess)
                {
                    LeadDataService
                    .SetSuccessfulPlacementCheck(lead.SetSessionId(placementCheckResponse.SessionId), true)
                    .SaveAsync(lead);
                }


                return(placementCheckResponse);
            }
            catch (Exception ex)
            {
                return(new { isKosher = false });
            }
        }