Reputation: 113
I am creating an async task in a repo, and then accessing it from the controller to try and minimize the logic in the controller.
The thing is, that when I used the exact same logic in the controller, there was an output, now that I'm accessing this way, it isn't searching for it.
Repository:
public async Task<List<Guests>> GetGuesteByAsync(string Search)
{
var list = GetAll();
var listquery = from x in context.Guest select x;
if (!string.IsNullOrEmpty(Search))
{
listquery = listquery.Where(x => x.FullName.Contains(Search) || x.Organisation.Contains(Search));
}
return await context.Guests.ToListAsync();
}
The controller:
[HttpGet]
public async Task<ActionResult> Index(string Search)
{
ViewData["Getsearchinput"] = EmpSearch;
//List<Guests> listofguests = await repository.GetGuesteByAsync(Search);
var res = await (repository.GetGuesteByAsync(Search));
return View(res);
}
Upvotes: 1
Views: 129
Reputation: 794
This returns all entries.
return await context.Guests.ToListAsync();
I think you should use your query. Can you try this?
return await listquery.ToListAsync();
Upvotes: 1