Пример #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 });
            }
        }
Пример #2
0
        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 });
            }
        }