OTDL
C# api response infinitly loading and stops debuging with working api and blazor
// Blazor code method that gets the categories and applies pagination and such
private async Task GetCategories()
{
ViewModel.IsLoading = true;
var categories = await CategoryService.GetCategories(null);
ViewModel.TotalItems = categories.Count();
ViewModel.TotalPages = ViewModel.TotalItems / ViewModel.PageSize;
if (ViewModel.TotalItems % ViewModel.PageSize != 0)
{
ViewModel.TotalPages++;
}
int startIndex = (ViewModel.CurrentPage - 1) * ViewModel.PageSize;
int endIndex = Math.Min(startIndex + ViewModel.PageSize, ViewModel.TotalItems);
var categoriesResponse = categories.Skip(startIndex).Take(ViewModel.PageSize).ToList();
ViewModel.CategoriesList = categoriesResponse.Select(async x =>
{
var count = await GetItemsInCategory(x.Id);
return new CategoryViewModel
{
Id = x.Id,
Name = x.Name,
Count = count
};
}).Select(t => t.Result).ToList();
ViewModel.IsLoading = false;
}
// Blazor code method that gets the amount in category, its currently using the second api method code would be different with the first one
private async Task<int> GetItemsInCategory(Guid id)
{
var products = await CategoryService.GetProductAmountByCategory(id);
return products;
}
Please help me if i need to add any other code or explanation say so.
6 replies