File tree Expand file tree Collapse file tree
exercise.wwwapi/Endpoints Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,14 +33,21 @@ public static void ConfigureAuthApi(this WebApplication app)
3333 [ Authorize ]
3434 [ ProducesResponseType ( StatusCodes . Status200OK ) ]
3535 [ ProducesResponseType ( StatusCodes . Status401Unauthorized ) ]
36- private static async Task < IResult > GetUsers ( IRepository < User > service , string ? firstName , ClaimsPrincipal user )
36+ private static async Task < IResult > GetUsers ( IRepository < User > service , string ? name , ClaimsPrincipal user )
3737 {
3838 IEnumerable < User > results = await service . Get ( ) ;
39- UsersSuccessDTO userData = new UsersSuccessDTO ( ) {
40- Users = ! string . IsNullOrEmpty ( firstName )
41- ? results . Where ( i => i . Email . Contains ( firstName ) ) . ToList ( )
42- : results . ToList ( ) } ;
43- ResponseDTO < UsersSuccessDTO > response = new ResponseDTO < UsersSuccessDTO > ( )
39+ string ? search = name ? . Trim ( ) . ToLower ( ) ;
40+ UsersSuccessDTO userData = new UsersSuccessDTO ( )
41+ {
42+ Users = ! string . IsNullOrWhiteSpace ( name )
43+ ? results . Where ( i =>
44+ ( i . FirstName . ToLower ( ) . Contains ( search ) ) ||
45+ ( i . LastName . ToLower ( ) . Contains ( search ) ) ||
46+ ( $ "{ i . FirstName ?? "" } { i . LastName ?? "" } ". ToLower ( ) . Contains ( search ) )
47+ ) . ToList ( )
48+ : results . ToList ( )
49+ } ;
50+ ResponseDTO < UsersSuccessDTO > response = new ResponseDTO < UsersSuccessDTO > ( )
4451 {
4552 Message = "success" ,
4653 Data = userData
You can’t perform that action at this time.
0 commit comments