correction sur la pagination

crud/security
Victor GABORIT 1 year ago
parent 6921fecd5b
commit f0441a48e2

@ -189,11 +189,11 @@ namespace ModelToEntity
}
}
public async Task<IEnumerable<User?>> GetItems(int index, int count, string? orderingPropertyName = null, object? valueProperty = null)
public async Task<IEnumerable<User?>> GetItems(int page, int count, string? orderingPropertyName = null, object? valueProperty = null)
{
using (var context = new UserDbContext())
{
var users = (await context.GetItemsWithFilter<UserEntity>(index, count, orderingPropertyName, valueProperty));
var users = (await context.GetItemsWithFilter<UserEntity>(page, count, orderingPropertyName, valueProperty));
if(users == null)
{
return null;

@ -74,7 +74,7 @@ namespace ModelToEntity
return Task.FromResult<T?>(entity);
}
internal static Task<IEnumerable<T?>> GetItemsWithFilter<T>(this DbContext context,
int index, int count, string? orderingPropertyName = null, object? valueProperty = null) where T : class
int page, int count, string? orderingPropertyName = null, object? valueProperty = null) where T : class
{
IQueryable<T> query = context.Set<T>();
@ -100,7 +100,7 @@ namespace ModelToEntity
}
return Task.FromResult<IEnumerable<T?>>(null);
}
var items = query.Skip(index).Take(count).ToList();
var items = query.Skip((page -1) * count).Take(count).ToList();
return Task.FromResult<IEnumerable<T?>>(items);
}
}

@ -78,9 +78,9 @@ namespace Services
return item.FromModelToDTO();
}
public async Task<IEnumerable<UserDTO?>> GetItems(int index, int count, string? orderingPropertyName = null, object? valueProperty = null)
public async Task<IEnumerable<UserDTO?>> GetItems(int page, int count, string? orderingPropertyName = null, object? valueProperty = null)
{
var items = await dataServiceEF.GetItems(index, count, orderingPropertyName, valueProperty);
var items = await dataServiceEF.GetItems(page, count, orderingPropertyName, valueProperty);
if (items == null)
{
throw new InvalidOperationException("aucune donnée trouvé");

Loading…
Cancel
Save