Exemplo n.º 1
0
        public void ProcessMessage(String text)
        {
            logger.Debug($"Processing incoming message: {text}");

            try
            {
                ContactUs       ContactUsModel = JsonConvert.DeserializeObject <ContactUs>(text);
                LeadDataService LeadService    = new LeadDataService();
                Entity          lead           = LeadService.BuildLeadFromContactUsModel(ContactUsModel);

                try
                {
                    LeadService.PushLeadToCrm(lead);
                }
                catch (System.ServiceModel.FaultException e)
                {
                    logger.Error($"Error Creating Lead from {ContactUsModel.ToString()} ");
                    logger.Error($"Message: {e.Message}");
                    throw;
                }
            }
            catch (JsonException e)
            {
                logger.Error($"Invalid Contact Us Message: {text}");
                logger.Error($"Message {e.Message}");
                logger.Error($"Inner Exception: {e.InnerException}");
                throw;
            }
        }
Exemplo n.º 2
0
        public object DoSemPlacementCheckLead([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 = SemProxyService.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 });
            }
        }
Exemplo n.º 3
0
        public object DoSemSubmitLead([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 = SemProxyService.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 });
            }
        }
Exemplo n.º 4
0
        public object UpdateStagedLead([FromBody] string jsonString, int id)
        {
            try
            {
                var leadApiParams = JsonConvert.DeserializeObject <Dto.LeadApiParams>(jsonString);

                if (leadApiParams.Id != id)
                {
                    throw new Exception("The Id in the JSON does not match the Id on the URL.");
                }


                var lead = Mapper.Map <Lead>(leadApiParams);
                LeadDataService.SaveAsync(lead);

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