Ejemplo n.º 1
0
        public async Task <IHttpActionResult> GetLeads(SearchLeadSimple leadSearcher)
        {
            //Log the request
            var logCommand = new LogCommand
            {
                User            = User,
                LoggingInstance = _loggingInstance,
                LogMessage      = $"LeadController.GetLead Starting input parameter LeadSearcher = {JsonConvert.SerializeObject(leadSearcher)}"
            };

            _logHandler.HandleLog(logCommand);

            //Await the response
            var results = await _leadService.GetLead(leadSearcher, logCommand);

            //Log the response
            logCommand.LogMessage =
                $"LeadController.GetLead completed. Output value = {JsonConvert.SerializeObject(results.Entity)}";
            _logHandler.HandleLog(logCommand);

            //Return the results
            return(ReturnFormattedResults(results));
        }
Ejemplo n.º 2
0
        public async Task <GenericServiceResponse> GetLead(SearchLeadSimple leadSearcher, LogCommand logCommand)
        {
            const string method = "GetLead";

            try
            {
                logCommand.LogMessage = string.Format($"{Service}.{method} Starting input parameter LeadSearcher = {JsonConvert.SerializeObject(0)}", leadSearcher);
                _logHandler.HandleLog(logCommand);

                var sfLeadList = await _leadRepository.GetSfLeads(leadSearcher, logCommand);

                var response = ServiceHelper.SetGenericServiceResponseForEntityList(sfLeadList);
                response.Success = true;

                logCommand.LogMessage = string.Format($"{Service}.{method} completed");
                _logHandler.HandleLog(logCommand);
                return(response);
            }
            catch (Exception ex)
            {
                AppLogger.LogException(_loggingInstance, ex.Message, ex);
                return(ServiceHelper.SetErrorGenericServiceResponse(ex));
            }
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <SFSimpleLeadResults> > GetSfLeads(SearchLeadSimple leadSearcher, LogCommand logCommand)
        {
            //Logging Helper String
            const string methodName = "GetSFLeads";

            if (leadSearcher.NumberOfRecords == null || leadSearcher.NumberOfRecords == 0 || leadSearcher.NumberOfRecords > 1000)
            {
                leadSearcher.NumberOfRecords = 1000;
            }


            //ToDo:: Fix this to match our strategy.
            //Query used by Dapper

            //Query Used by Dapper
            var query = new QueryBuilder($" select distinct TOP ({leadSearcher.NumberOfRecords})     " +
                                         " _lead.[LeadGuid]      " +
                                         " ,_Customer.[CustomerGuid]     " +
                                         " ,_Customer.[BillingAccountNumber] as BillAccount     " +
                                         " ,_Customer.[CMCCustomerID]    " +
                                         " ,_email.Email_Address as Email    " +
                                         " ,_phone.Phone as PhoneNumber    " +
                                         " ,_contact.FullName as CustomerName         " +
                                         " ,_address.Zip as ZipCode    " +
                                         " ,_county.CountyDescription as County    " +
                                         " ,_address.StreetAddress1 as STAddress  " +
                                         " ,CUU.CAPTier   " +
                                         " from [Customer].[Lead] as _lead     " +

                                         " join Customer.Customer as _Customer       " +
                                         " on _Customer.CustomerGuid = _lead.[CustomerGuid]     " +

                                         " join [Contact].Contact as _contact       " +
                                         " on _contact.[CustomerGuid] = _Customer.CustomerGuid     " +

                                         " left join [Contact].Email as _email       " +
                                         " on _email.ContactGuid = _contact.ContactGuid    " +

                                         " left join [Contact].Phone as _phone     " +
                                         " on _phone.ContactGuid = _contact.ContactGuid        " +

                                         " join Program.Program _program       " +
                                         " on _program.ProgramGuid = _Customer.ProgramGuid      " +

                                         "	CROSS APPLY(SELECT TOP 1 lrc.CapTier FROM [Customer].[Usage] CUU "+
                                         " INNER JOIN [UsageRaw].[LkpRateCodes] LRC ON LRC.RateCode = CUU.Rate  " +

                                         " AND LRC.ProgramGuid = _Customer.ProgramGuid " +
                                         " WHERE CUU.CustomerGuid = _Customer.CustomerGuid) CUU " +

                                         " join Program.Subprogram _subprogram     " +
                                         " on _subprogram.SubProgramGuid = _Customer.SubProgramGuid     " +

                                         " join [Customer].[Address] as _address  " +
                                         " on _address.CustomerGuid = _Customer.CustomerGuid " +

                                         " join [Customer].[LkpCounties] as _county  " +
                                         " on _address.CountyGuid = _county.CountyGuid ");

            query.WhereAndCondition("_lead.SFLeadID is null");
            query.WhereAndCondition($"_email.Email_Address like '%'+@EmailAddress+'%'", leadSearcher.EmailAddress);
            query.WhereAndCondition($"_contact.FullName like '%'+@CustomerName+'%'", leadSearcher.CustomerName);
            query.WhereAndCondition($"_Customer.CMCCustomerID = @CMCCustomerID", leadSearcher.CMCCustomerID);
            query.WhereAndCondition($"_Customer.BillingAccountNumber like '%'+@BillAccount+'%'", leadSearcher.BillAccount);
            query.WhereAndCondition($"_address.Zip like '%'+@ZipCode+'%' ", leadSearcher.ZipCode);
            query.WhereAndCondition($"_address.StreetAddress1 like '%'+@StAddress+'%' ", leadSearcher.StAddress);
            query.WhereAndCondition($"( _phone.[Phone] like '%' + @PhoneNumber + '%' or _phone.[Mobile] like '%' + @PhoneNumber + '%' or _phone.[Home_Phone__c] like '%'+ @PhoneNumber + '%' )", leadSearcher.PhoneNumber);
            query.WhereAndCondition($"(_Customer.ProgramId = @ProgramGuid)", leadSearcher.ProgramGuid);


            //Log the input
            logCommand.LogMessage = $"{Repository}.{methodName} Starting no input parameter LeadSearcher={JsonConvert.SerializeObject(leadSearcher)}" + Environment.NewLine +
                                    $"Query: {query.GetQuery()}";
            _logHandler.HandleLog(logCommand);

            using (var connection = _connectionFactory.GetConnection)
            {
                //Await the response
                var leadList = await connection.QueryAsync <SFSimpleLeadResults>(query.GetQuery(), leadSearcher);

                connection.Close();

                //Log the output
                logCommand.LogMessage = $"{Repository}.{methodName} completed";
                _logHandler.HandleLog(logCommand);

                return(leadList);
            }
        }