예제 #1
0
        /// <summary>
        /// Gets the leads.
        /// </summary>
        /// <param name="leadParameters">The lead parameters.</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task <APIResponse> GetLeads(LeadParameters leadParameters)
        {
            try
            {
                var client = httpClientFactory.CreateClient(LeadServiceOperation.serviceName);

                UriBuilder url = new UriBuilder(servicesConfig.Lead + LeadServiceOperation.GetLeads());

                url.Query = QueryStringHelper.ConvertToQueryString(leadParameters);

                var response = await client.GetAsync(url.ToString());

                if (response.IsSuccessStatusCode)
                {
                    var leads = JsonConvert.DeserializeObject <List <LeadDataCollectionResponse> >(await response.Content.ReadAsStringAsync());

                    return(new APIResponse(leads, HttpStatusCode.OK));
                }

                return(new APIResponse(response.StatusCode));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'GetLeads()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
예제 #2
0
        /// <summary>
        /// Gets all leads.
        /// </summary>
        /// <param name="leadParameters">The lead parameters.</param>
        /// <returns></returns>
        public async Task <PagedList <Entity> > GetAllLeads(LeadParameters leadParameters)
        {
            var leadCollections = FindByCondition(x => x.Active == Convert.ToInt16(true) && x.Leads.All(x => x.Active == Convert.ToInt16(true)))
                                  .ProjectTo <LeadDataCollectionResponse>(mapper.ConfigurationProvider);

            SearchByPhoneNoOrLeadId(ref leadCollections, leadParameters);
            FilterByDate(ref leadCollections, leadParameters.FromDate, leadParameters.ToDate);
            var sortedStories = sortHelper.ApplySort(leadCollections, leadParameters.OrderBy);
            var shapedStories = dataShaper.ShapeData(sortedStories, leadParameters.Fields);

            return(await PagedList <Entity> .ToPagedList(shapedStories, leadParameters.PageNumber, leadParameters.PageSize));
        }
예제 #3
0
        public async Task <IActionResult> GetLeads([FromQuery] LeadParameters leadParameters)
        {
            var getAlllLeadsQuery = new GetAllLeadsQuery(leadParameters);
            var result            = await mediator.Send(getAlllLeadsQuery);

            if (result.Code == HttpStatusCode.OK)
            {
                Response.Headers.Add("X-Pagination", PagedList <Entity> .ToJson(result.Value as PagedList <Entity>));
            }

            return(StatusCode((int)result.Code, result.Value));
        }
예제 #4
0
        /// <summary>
        /// Searches the by title or description.
        /// </summary>
        /// <param name="leadCollections">The lead datas.</param>
        /// <param name="searchText">The search text.</param>
        private void SearchByPhoneNoOrLeadId(ref IQueryable <LeadDataCollectionResponse> leadCollections, LeadParameters leadParameters)
        {
            if (!leadCollections.Any() ||
                string.IsNullOrWhiteSpace(leadParameters.PhoneNumber) || string.IsNullOrWhiteSpace(leadParameters.LeadId))
            {
                return;
            }

            if (nameof(LeadDataCollectionResponse.CustomerPhone1).Equals(leadParameters.SearchKeyword, StringComparison.OrdinalIgnoreCase))
            {
                leadCollections = leadCollections.Where(x => x.CustomerPhone1 == leadParameters.PhoneNumber);
            }
            else if (nameof(LeadsResponse.LeadId).Equals(leadParameters.SearchKeyword, StringComparison.OrdinalIgnoreCase))
            {
                leadCollections = leadCollections.Where(x => x.Leads.Any(y => y.LeadId == leadParameters.LeadId))
                                  .Include(x => x.Leads.Where(y => y.LeadId == leadParameters.LeadId));
            }
        }
        public async Task <IActionResult> GetLeads([FromQuery] LeadParameters leadParameters)
        {
            var result = await leadService.GetLeads(leadParameters);

            return(StatusCode((int)result.Code, result.Value));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetAllLeadsQuery"/> class.
 /// </summary>
 /// <param name="leadParameters">The lead parameters.</param>
 public GetAllLeadsQuery(LeadParameters leadParameters)
 {
     LeadParameters = leadParameters;
 }