dimanche 10 mars 2019

How to narrow search result by filtering by area/location

The project I'm working on is an ASP.NET Web api, Angular 7 project. I'm attempting to filter my result by location/area through the use of Angular 7 material design check boxes.

The result I'm wanting to filter are users that are located in specific locations. So when an administrator logs in, they would be able to view all of their users within their area. For example, if this admin is located in Minnesota, they would only view users in that state. Now I want to further filter the users by a series of check boxes. N.B. An admin can be located in one or many states.

I'm new to Angular and angular material design. So any guidance would be very much appreciated.

The below is the code that I have so far:

.Net

 //gets the logged in admin's location/locations saved in a claim
 //result: Minnesota, California etc.
 public IEnumerable<State> GetLoggedInAdminLocation(){

   var adminsLoggedInLocation = _httpContextAccessor.HttpContext.User.AdminLocation();

  return adminsLoggedInLocation; 
 }

 //gets users in admins state
 public IEnumerable<Users> GetUsersByState()
    {
        var adminsLoggedInLocation = _httpContextAccessor.HttpContext.User.AdminLocation();

        var getUsers = _sdsContext.State
            .Where(x => adminsLoggedInLocation 
            .Contains(x.StateName))
            .Select(x => x.Users).Distinct();
        return getUsers;
    }

   //function with a location parameter. Filters users further by location
  //Not sure if this is the right approach
   public IEnumerable<Users> FilterByLocation (IEnumerable<string> location)
    {
        var adminsLoggedInLocation = _httpContextAccessor.HttpContext.User.AdminLocation();

        var filterUsersByLocation = _sdsContext.UserAuthority
            .Where(x => adminsLoggedInLocation == location)
            .Select(x => x.Users).ToList();

        return filterUsersByLocation;
    }

Angular 7

.ts

getAdminLocations() {
return this.service.getAdminLocations();
}    

getUsers(){
return this.service.getAllAdminUsers();
}

filterUsers(this.model) {
return this.service.filterUsersByLocation();
}

service

getAdminLocations() {
return this.http.get(this.url + 'adminLocations')
}

getAllAdminUsers() {
return this.http.get(this.url + 'getAllUsers');
}

filterUsersByLocation(model: any) {
return this.http.post(this.url + 'filterByLocation');
}




Aucun commentaire:

Enregistrer un commentaire