Introduces MassData management to backend and Blazor frontend: - Adds API endpoint for MassData count and paging - Updates repository and controller for count support - Implements MediatR query/handler for count - Adds Blazor page and grid for viewing/editing MassData - Registers MassDataApiClient and integrates with DI - Supports paging, upsert, and UI feedback in grid
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System.Net.Http.Json;
|
|
using DbFirst.BlazorWebApp.Models;
|
|
|
|
namespace DbFirst.BlazorWebApp.Services;
|
|
|
|
public class MassDataApiClient
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private const string Endpoint = "api/massdata";
|
|
|
|
public MassDataApiClient(HttpClient httpClient)
|
|
{
|
|
_httpClient = httpClient;
|
|
}
|
|
|
|
public async Task<int> GetCountAsync()
|
|
{
|
|
var result = await _httpClient.GetFromJsonAsync<int?>("api/massdata/count");
|
|
return result ?? 0;
|
|
}
|
|
|
|
public async Task<List<MassDataReadDto>> GetAllAsync(int skip, int take)
|
|
{
|
|
var result = await _httpClient.GetFromJsonAsync<List<MassDataReadDto>>($"{Endpoint}?skip={skip}&take={take}");
|
|
return result ?? new List<MassDataReadDto>();
|
|
}
|
|
|
|
public async Task<MassDataReadDto> UpsertAsync(MassDataWriteDto dto)
|
|
{
|
|
var response = await _httpClient.PostAsJsonAsync($"{Endpoint}/upsert", dto);
|
|
response.EnsureSuccessStatusCode();
|
|
var payload = await response.Content.ReadFromJsonAsync<MassDataReadDto>();
|
|
return payload ?? new MassDataReadDto();
|
|
}
|
|
}
|