phronCare/phronCare.UIBlazor/Services/Stock/LSUnitOfMeasureService.cs
Leandro Hernan Rojas 6e592bd034
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 6m50s
Add UnitOfMeasure Search and Form
2025-07-15 12:42:30 -03:00

42 lines
1.3 KiB
C#

using Domain.Entities;
using Domain.Generics;
using System.Net.Http.Json;
namespace phronCare.UIBlazor.Services.Stock
{
public class LSUnitOfMeasureService
{
private readonly HttpClient _http;
public LSUnitOfMeasureService(HttpClient http)
{
_http = http;
}
public async Task<PagedResult<ELSUnitOfMeasure>> SearchAsync(string? term, int page = 1, int pageSize = 50)
{
var response = await _http.GetFromJsonAsync<PagedResult<ELSUnitOfMeasure>>(
$"api/LSUnitOfMeasure/Search?term={term}&page={page}&pageSize={pageSize}");
return response!;
}
public async Task<ELSUnitOfMeasure?> GetByIdAsync(int id)
{
return await _http.GetFromJsonAsync<ELSUnitOfMeasure>($"api/LSUnitOfMeasure/GetById/{id}");
}
public async Task<int> CreateAsync(ELSUnitOfMeasure model)
{
var response = await _http.PostAsJsonAsync("api/LSUnitOfMeasure/Create", model);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<int>();
}
public async Task UpdateAsync(ELSUnitOfMeasure model)
{
var response = await _http.PutAsJsonAsync("api/LSUnitOfMeasure/Update", model);
response.EnsureSuccessStatusCode();
}
}
}