-1

Can u please help me?

I've project in ASP.NET CORE API where is a database of exams. I need filter it by class. For example: I have a list of exams for whole school and i want to display JSON for only one class exams.

I wrote code from: Microsoft Docs (https://learn.microsoft.com/cs-cz/aspnet/core/web-api/advanced/formatting?view=aspnetcore-3.1) but my Visual Studio didn't recognised "GetByNameSubstring". What can I do?

//GET: api/authors/search?namelike=th
    [HttpGet("Search")]
    public IActionResult Search(string namelike)
    {
        var result = _context.GetByNameSubstring(namelike);
        if (!result.Any())
        {
            return NotFound(namelike);
        }
        return Ok(result);
    } 

my code in VS2019

Martin
  • 33
  • 7

1 Answers1

1

The method GetByNameSubstring(string nameSubstring) is not a built in method; it's a method defined in the Authors class of the sample. If you want that method, you will have to add it, or extend your _context class.

The implementation is in the sample code:

public List<Author> GetByNameSubstring(string nameSubstring)
{
  return List()
    .Where(a =>
      a.Name.IndexOf(nameSubstring, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
      .ToList();
}
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Michel Jansson
  • 1,803
  • 1
  • 13
  • 14