private Task <List <Author> > SearchAuthors(AuthorSearchForm authorSearchForm) { return(Task.Run(() => { IQueryable <Author> authorIQuer = _db.Authors; List <Author> searchedResult = new List <Author>(); if (!string.IsNullOrWhiteSpace(authorSearchForm.textBoxSearchFirstName.Text)) { authorIQuer = authorIQuer.Where(p => p.FirstName.Contains(authorSearchForm.textBoxSearchFirstName.Text)); } if (!string.IsNullOrWhiteSpace(authorSearchForm.textBoxSearchSecondName.Text)) { authorIQuer = authorIQuer.Where(p => p.SecondName.Contains(authorSearchForm.textBoxSearchSecondName.Text)); } DateTime birthDate = DateTime.Now; if (!string.IsNullOrWhiteSpace(authorSearchForm.textBoxSearchBirth.Text) && DateTime.TryParse(authorSearchForm.textBoxSearchBirth.Text, out birthDate)) { authorIQuer = authorIQuer.Where(p => p.BirthDate == birthDate); } searchedResult.AddRange(authorIQuer.ToList <Author>()); return searchedResult; })); }
private async void btnAuthorSearch_Click(object sender, EventArgs e) { AuthorSearchForm authorSearchForm = new AuthorSearchForm(); DialogResult result = authorSearchForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } SearchedAuthors.Clear(); SearchedAuthors = await SearchAuthors(authorSearchForm); bindingSourceAuthorSearch.DataSource = SearchedAuthors; dataGridViewAuthors.DataSource = bindingSourceAuthorSearch; }