Burdy
Burdy

Reputation: 113

Nothing happens when accessing an async task from repository in asp.net?

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

Answers (1)

Mustafa Arslan
Mustafa Arslan

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

Related Questions