Home > Net >  How can I implement a search functionality in .NET MAUI using SQLite?
How can I implement a search functionality in .NET MAUI using SQLite?

Time:08-24

I want to implement search functionality to filter through all my projects for a storybook illustrator company. This is how I get all the projects to show in my front-end, but I want to search for a specific project by name and ID. Any ideas?

[RelayCommand]
       public async void GetProjectList()
       {
           Projects.Clear();
           var projectList = await _projectService.GetProjectList();
           if (projectList?.Count > 0)
           {
               foreach (var project in projectList)
               {
                   Projects.Add(project);
               }
           }
       }

CodePudding user response:

[RelayCommand]
public async void ProjectSearchItems()
{
    var projectList = await _projectService.GetProjectList();
    var searchedName = projectList.Where(value => value.ProjectName.ToLowerInvariant().Contains("//var from frontend searchbar")).ToList();
    var searchedID = projectList.Where(value => value.ProjectID.ToString().Contains("//var from frontend searchbar")).ToList();

    //Clearing previous projects
    Projects.Clear();
    foreach (var project in searchedName)
    {
        //add Projectname searched to List
        Projects.Add(project);
    }
    foreach (var project in searchedID)
    {
        //add ProjectID searched to List
        Projects.Add(project);
    }
}
  • Related