Ejemplo n.º 1
0
 public async Task <ActionResult> QueryUsers(UserFilter filter)
 {
     try
     {
         var res   = filter.BuildQuery(_context.Users).Include(x => x.UserRoles).ToList();
         var total = res.Count();
         if (filter.Pager.Page > 0)
         {
             res = res.Skip(filter.Pager.Skip()).Take(filter.Pager.Size).ToList();
         }
         if (!res.Any())
         {
             return(NotFound(new { Message = "No User Found" }));
         }
         var data = res.Select(x => new
         {
             x.Id,
             x.Name,
             x.Email,
             x.PhoneNumber,
             x.UserName,
             Role = new RoleRepository(_context).GetById(x.UserRoles.First().RoleId)?.Name,
         }).ToList();
         return(Ok(data));
     }
     catch (Exception ex)
     {
         return(BadRequest(WebHelpers.ProcessException(ex)));
     }
 }