public HttpResponseMessage Get( HttpRequestMessage request, [FromUri]string query, [FromUri]BusinessType[] type, [FromUri]string city, [FromUri]string state, [FromUri]string postal, [FromUri]int? distance, [FromUri]int[] scopeId) { CompanySearchResultItem[] result = new CompanySearchResultItem[0]; List<CompanyProfile> companies = new List<CompanyProfile>(); if ((type != null && type.Length > 0) && distance.HasValue && (city != null || state != null || postal != null) && (scopeId != null && scopeId.Length > 0)) { companies = _service.SearchCompanyProfiles( query == null ? "" : query, type, city == null ? "" : city, state == null ? "" : state, postal == null ? "" : postal, Convert.ToDouble(distance.Value), scopeId ).ToList(); } else if ((type != null && type.Length > 0) && distance.HasValue && (city != null || state != null || postal != null) && (scopeId == null || scopeId.Length == 0)) { companies = _service.SearchCompanyProfiles( query == null ? "" : query, type, city == null ? "" : city, state == null ? "" : state, postal == null ? "" : postal, Convert.ToDouble(distance.Value) ).ToList(); } else if ((type == null || type.Length == 0) && distance.HasValue && (city != null || state != null || postal != null) && (scopeId != null && scopeId.Length > 0)) { companies = _service.SearchCompanyProfiles( query == null ? "" : query, city == null ? "" : city, state == null ? "" : state, postal == null ? "" : postal, Convert.ToDouble(distance.Value), scopeId ).ToList(); } else if ((type == null || type.Length == 0) && distance.HasValue && (city != null || state != null || postal != null) && (scopeId == null || scopeId.Length == 0)) { companies = _service.SearchCompanyProfiles( query == null ? "" : query, city == null ? "" : city, state == null ? "" : state, postal == null ? "" : postal, Convert.ToDouble(distance.Value) ).ToList(); } else if ((type != null && type.Length > 0) && !distance.HasValue && (scopeId != null && scopeId.Length > 0)) { companies = _service.SearchCompanyProfiles( query == null ? "" : query, type, scopeId ).ToList(); } else if ((type != null && type.Length > 0) && !distance.HasValue && (scopeId == null || scopeId.Length == 0)) { companies = _service.SearchCompanyProfiles( query == null ? "" : query, type ).ToList(); } else if ((type == null || type.Length == 0) && !distance.HasValue && (scopeId != null && scopeId.Length > 0)) { companies = _service.SearchCompanyProfiles( query == null ? "" : query, scopeId ).ToList(); } else { companies = _service.SearchCompanyProfiles(query == null ? "" : query).ToList(); } result = companies.Where(x => x.Id != 1).Select(s => new CompanySearchResultItem { CompanyId = s.Id, CompanyName = s.CompanyName, LinkPath = Url.Link("Default", new { controller = "Company", action = "Profile", id = s.Id }), BusinessType = s.BusinessType.ToDescription(), ScopesOfWork = s.Scopes.Select(c => c.Scope).ToDictionary(x => x.Id, x => x.CsiNumber + " " + x.Description) }) .ToArray(); return request.CreateResponse(HttpStatusCode.OK, result); }
private CompanySearchResultItem companySearchResultItemMapper(CompanyProfile company) { CompanySearchResultItem result = new CompanySearchResultItem { CompanyId = company.Id, CompanyName = company.CompanyName, LinkPath = Url.Link("Default", new { controller = "Company", action = "Profile", id = company.Id }), BusinessType = company.BusinessType.ToDescription(), Area = company.City != null ? company.City + ", " + company.State.Abbr : "", ScopesOfWork = company.Scopes == null || company.Scopes.Count == 0 ? default(Dictionary<int, string>) : company.Scopes.Where(c => c.Scope.Children == null || c.Scope.Children.Count == 0).Select(s => s.Scope).ToDictionary(s => s.Id, s => s.CsiNumber + " " + s.Description) }; return result; }