Beispiel #1
0
        private IQueryable <Company> GetSearchQuery(CompanySearchDto searchDto)
        {
            var query = _context.Companies
                        .OrderByDescending(c => c.ChangeDate)
                        .Include(c => c.Subscriptions).ThenInclude(s => s.Tariff)
                        .AsQueryable();

            if (!string.IsNullOrEmpty(searchDto.Email))
            {
                query = query.Where(c => c.Email == searchDto.Email);
            }

            if (!string.IsNullOrEmpty(searchDto.INN))
            {
                query = query.Where(c => c.INN == searchDto.INN);
            }

            if (!string.IsNullOrEmpty(searchDto.Name))
            {
                query = query.Where(c => c.Name.Contains(searchDto.Name));
            }

            if (searchDto.TariffId.HasValue)
            {
                query = query.Where(c => c.Subscriptions.Any(s => s.Active && s.Tariff.Id == searchDto.TariffId.Value && s.EndDate >= DateTime.Now.Date));
            }

            return(query);
        }
        public async Task <IActionResult> SearchCompaniesAsync(SearchCompaniesViewModel searchModel)
        {
            try
            {
                CompanySearchDto searchDto = new CompanySearchDto
                {
                    Title   = searchModel.Title,
                    Address = searchModel.Address
                };

                var companies = await companyService.SearchCompaniesAsync(searchDto);

                CompaniesListViewModel viewModel = new CompaniesListViewModel()
                {
                    Companies = companies
                };

                return(View("Views/Company/CompaniesList.cshtml", viewModel));
            }
            catch (Exception ex)
            {
                ErrorViewModel errorModel = new ErrorViewModel();
                errorModel.ErrorMessage = ex.Message.ToString();

                return(View("Views/Shared/Error.cshtml", errorModel));
            }
        }
Beispiel #3
0
        public async Task <PagedResult <CompanyListDto> > GetCompanies(CompanySearchDto searchDto, int pageSize = 20, int pageNumber = 1)
        {
            var querry        = GetSearchQuery(searchDto);
            var pagedEntities = await querry.GetPagedResult(pageSize, pageNumber);

            return(_mapper.Map <PagedResult <CompanyListDto> >(pagedEntities));
        }
        public object GetCompanyDetailsFromName(string searchTerm)
        {
            WebRequest webReq = GetWebRequest(SEARCH + "?q=" + searchTerm + "&items_per_page=20&start_index=0");

            HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();

            Stream answer = response.GetResponseStream();

            using (var sr = new StreamReader(answer))
                using (var jsonTextReader = new JsonTextReader(sr))
                {
                    var serializer = new JsonSerializer();
                    //dynamic obj= (CompaniesDto)serializer.Deserialize(jsonTextReader);
                    string json = sr.ReadToEnd();
                    // "{'page_number': 1,'start_index': 0,'kind': 'search#all','items_per_page': 20,'total_results': 53, items: []}";
                    //  "{'page_number': 1,'start_index': 0,'kind': 'search#all','items_per_page': 20,'total_results': 53,'items': [{'address_snippet': 'Aspect House, Spencer Road, Lancing, West Sussex, BN99 6DA','description_identifier': ['incorporated-on'],'title': 'EQUINITI LIMITED','company_number': '06226088','description': '06226088 - Incorporated on 25 April 2007','kind': 'searchresults#company','company_status': 'active','date_of_creation': '2007-04-25','links': {'self': '/company/06226088'},'company_type': 'ltd','matches': {'snippet': [],'title': [1,8]},'address': {'region': 'West Sussex','address_line_1': 'Spencer Road','locality': 'Lancing','postal_code': 'BN99 6DA','premises': 'Aspect House'},'snippet': ''}]}";
                    CompanySearchDto obj = JsonConvert.DeserializeObject <CompanySearchDto>(json);

                    if (obj.items == null || obj.items.Count == 0)
                    {
                        return(null);
                    }
                    else
                    {
                        return(GetCompanyDetails(obj.items[0].links.self));
                    }
                }
        }
Beispiel #5
0
        public async Task <List <CompanyDto> > SearchCompaniesAsync(CompanySearchDto searchDto)
        {
            var companies = await dbContext.Company.Where(c => ((searchDto.Title == null) || ((searchDto.Title != null) && c.Title == searchDto.Title)) &&
                                                          ((searchDto.Address == null) || ((searchDto.Address != null) && c.Address == searchDto.Address)))
                            .ToListAsync();

            var companiesDtos = companies.Select(c => mapper.Map <CompanyDto>(c)).ToList();

            return(companiesDtos);
        }
        public async Task <List <CompanyDto> > SearchCompaniesAsync(CompanySearchDto searchDto)
        {
            var companies = await litigationPlannerUnitOfWork.CompanyRepository.SearchCompaniesAsync(searchDto);

            return(companies);
        }
Beispiel #7
0
        public async Task <ActionResult <IEnumerable <CompanyReadDto> > > SearchAsync(CompanySearchDto companySearchDto)
        {
            var query = _queryBuilder.GetAll();

            query = !string.IsNullOrEmpty(companySearchDto.Keyword)
                ? query.NameLike(companySearchDto.Keyword)
                : query;

            query = companySearchDto.EmployeeJobTitles != null && companySearchDto.EmployeeJobTitles.Any()
                ? query.WithEmployeeAtJobs(companySearchDto.EmployeeJobTitles)
                : query;

            query = companySearchDto.EmployeeDateOfBirthFrom.HasValue
                ? query.WithEmployeeBornAfter(companySearchDto.EmployeeDateOfBirthFrom.Value)
                : query;

            query = companySearchDto.EmployeeDateOfBirthTo.HasValue
                ? query.WithEmployeeBornBefore(companySearchDto.EmployeeDateOfBirthTo.Value)
                : query;

            return(Ok(await query.ToListAsync()));
        }
Beispiel #8
0
        public async Task <IActionResult> GetAll([FromBody] CompanySearchDto searchDto, int pageSize, int pageNumber)
        {
            var dtos = await _companyService.GetCompanies(searchDto, pageSize, pageNumber);

            return(Ok(dtos));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
                          .Value;

            if (name == null)
            {
                // Get request body
                dynamic data = await req.Content.ReadAsAsync <object>();

                name = data?.name;
            }

            if (name == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body"));
            }
            else
            {
                WebRequest webReq = GetWebRequest(SEARCH + "?q=" + name + "&items_per_page=20&start_index=0");

                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                Stream          answer   = response.GetResponseStream();

                CompanySearchDto searchResult = null;
                using (var sr = new StreamReader(answer))
                    using (var jsonTextReader = new JsonTextReader(sr))
                    {
                        var    serializer = new JsonSerializer();
                        string json       = sr.ReadToEnd();
                        //string json = "{'page_number': 1,'start_index': 0,'kind': 'search#all','items_per_page': 20,'total_results': 53, items: []}";
                        //string json = "{'page_number': 1,'start_index': 0,'kind': 'search#all','items_per_page': 20,'total_results': 53,'items': [{'address_snippet': 'Aspect House, Spencer Road, Lancing, West Sussex, BN99 6DA','description_identifier': ['incorporated-on'],'title': 'EQUINITI LIMITED','company_number': '06226088','description': '06226088 - Incorporated on 25 April 2007','kind': 'searchresults#company','company_status': 'active','date_of_creation': '2007-04-25','links': {'self': '/company/06226088'},'company_type': 'ltd','matches': {'snippet': [],'title': [1,8]},'address': {'region': 'West Sussex','address_line_1': 'Spencer Road','locality': 'Lancing', 'country': 'Great Britain','postal_code': 'BN99 6DA','premises': 'Aspect House'},'snippet': ''}]}";
                        var settings = new JsonSerializerSettings {
                            Error = (se, ev) => { ev.ErrorContext.Handled = true; }
                        };

                        searchResult = JsonConvert.DeserializeObject <CompanySearchDto>(json, settings);
                    }
                if (searchResult.items == null || searchResult.items.Count == 0)
                {
                    return(req.CreateResponse(HttpStatusCode.InternalServerError, "No data returned from Companies House."));
                }
                else
                {
                    //get the link of the first item
                    string            companylink = searchResult.items.First().links.self;
                    CompanyProfileDTO company     = GetSpecificCompanyDetails(companylink);
                    //Check that the company is not null
                    if (company == null)
                    {
                        return(req.CreateResponse(HttpStatusCode.InternalServerError, "Company details could not be retrieved."));
                    }

                    List <CompanyOfficerDTO> directorList = null;
                    string officersLink = company.links.officers;
                    if (officersLink != null && officersLink.Length > 0)
                    {
                        directorList = GetDirectorDetails(officersLink);
                    }
                    //do no check if ththe list of directors is null or empty. If there are no directors we shall return nothing

                    var relevantInfo = new RelevantCompanyInfoDTO();
                    relevantInfo.CompanyName             = company.company_name;
                    relevantInfo.PreviousNames           = company.previous_company_names;
                    relevantInfo.CompanyStatus           = company.company_status;
                    relevantInfo.CompanyType             = company.type;
                    relevantInfo.HasBeenLiquidatedInPast = company.has_been_liquidated;
                    relevantInfo.HasInsolvencyHistory    = company.has_insolvency_history;
                    relevantInfo.RegisteredAddress       = company.registered_office_address;
                    relevantInfo.DirectorList            = directorList;
                    return(req.CreateResponse(HttpStatusCode.OK, relevantInfo));
                }
            }

            //return name == null
            //    ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
            //    : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
        }