public ListGetResponse SearchCompanies(long?tin, int?companyType, string title, Guid?founderId, int pageSize, int pageNumber) { ListGetResponse response = new ListGetResponse(); CompanyType?type = null; if (companyType != null) { type = (CompanyType)companyType.Value; } CompanySearchQuery query = new CompanySearchQuery() { Tin = tin ?? null, Title = title ?? string.Empty, CompanyType = type, FounderId = founderId ?? null, PageSize = pageSize, PageNumber = pageNumber }; foreach (Company company in companyService.Search(query)) { response.Items.Add(entityConverter.GetListItemModel(company)); } return(response); }
public IList <Company> Search(SearchQueryBase <Company> searchQuery) { CompanySearchQuery query = searchQuery as CompanySearchQuery; IQueryable <Company> result; if (query.Tin != null) { result = context .GetDbSet <Company>() .Where(c => c.Tin == query.Tin.Value && !c.IsDeleted); } else { if (query.FounderId != null) { result = context .GetDbSet <FounderToCompany>() .Where(r => r.Founder.Id == query.FounderId && !r.IsDeleted) .Select(r => r.Company) .Where(c => !c.IsDeleted); } else { result = context .GetDbSet <Company>() .Where(c => !c.IsDeleted); } if (!string.IsNullOrEmpty(query.Title)) { result = result.Where(c => c.Title.Contains(query.Title)); } if (query.CompanyType != null) { result = result.Where(c => c.Type == query.CompanyType.Value); } } return(result .Page(searchQuery.PageNumber, searchQuery.PageSize) .ToArray()); }
public async Task <Company> GetCompany(string key) { var queryLog = new CompanySearchQuery(key); Company result; if (_nipWithCountryCodeRegex.IsMatch(key)) { result = await GetCompanyByNipWithCountryCode(key); queryLog.QueryType = QueryType.Nip; } else { result = await GetCompanyByKey(key); if (result?.Nip == key) { queryLog.QueryType = QueryType.Nip; } else if (result?.Krs == key) { queryLog.QueryType = QueryType.Krs; } else if (result?.Regon == key) { queryLog.QueryType = QueryType.Regon; } else { queryLog.QueryType = QueryType.Undefined; } } _queryHistoryService.LogQuery(queryLog); return(result); }
public void LogQuery(CompanySearchQuery queryLog) { _context.SearchQueries.Add(queryLog); _context.SaveChanges(); }