public async Task <IActionResult> Search([FromQuery] ProjectSearchRequest searchRequest) { return(await FunctionWrapper.ExecuteFunction(this, async() => { return await _projectRepository.Search(searchRequest); })); }
public async Task <IEnumerable <Project> > Search(ProjectSearchRequest searchRequest) { try { List <FilterDefinition <Project> > filters = new List <FilterDefinition <Project> >(); if (!string.IsNullOrEmpty(searchRequest.Name)) { filters.Add(Builders <Project> .Filter.Regex("Name", new BsonRegularExpression($".*{searchRequest.Name}.*"))); } var filterConcat = Builders <Project> .Filter.And(filters); return(await _context.Projects.Find(filterConcat).ToListAsync()); } catch (Exception ex) { throw ex; } }