Files
blazor-cms/Features/Thirdparty/PatientCategory/PatientCategoryService.cs
T
2026-07-21 13:52:43 +07:00

60 lines
2.4 KiB
C#

using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Thirdparty.PatientCategory.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Thirdparty.PatientCategory;
public class PatientCategoryService : BaseService
{
private readonly RestClient _client;
public PatientCategoryService(
IHttpClientFactory clientFactory,
NavigationManager nav,
ISnackbar snackbar,
ICurrentUserService currentUserService,
TokenProvider tokenProvider)
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
{
_client = new RestClient(nav.BaseUri);
}
public async Task<ApiResponse<List<GetPatientCategoryListResponse>>?> GetPatientCategoryListAsync()
{
var request = new RestRequest("api/patient-category", Method.Get);
return await ExecuteWithResponseAsync<List<GetPatientCategoryListResponse>>(_client, request);
}
public async Task<ApiResponse<GetPatientCategoryByIdResponse>?> GetPatientCategoryByIdAsync(string id)
{
var request = new RestRequest($"api/patient-category/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetPatientCategoryByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreatePatientCategoryResponse>?> CreatePatientCategoryAsync(CreatePatientCategoryRequest data)
{
var request = new RestRequest("api/patient-category", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreatePatientCategoryResponse>(_client, request);
}
public async Task<bool> DeletePatientCategoryByIdAsync(string id)
{
var request = new RestRequest($"api/patient-category/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<UpdatePatientCategoryResponse>?> UpdatePatientCategoryAsync(UpdatePatientCategoryRequest data)
{
var request = new RestRequest("api/patient-category/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdatePatientCategoryResponse>(_client, request);
}
}