Files
blazor-saas-hrm/Features/Payroll/Deduction/DeductionService.cs
T
2026-07-21 14:22:06 +07:00

59 lines
2.2 KiB
C#

using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Payroll.Deduction.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Payroll.Deduction;
public class DeductionService : BaseService
{
private readonly RestClient _client;
public DeductionService(
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<GetDeductionListResponse>>?> GetDeductionListAsync()
{
var request = new RestRequest("api/deduction", Method.Get);
return await ExecuteWithResponseAsync<List<GetDeductionListResponse>>(_client, request);
}
public async Task<ApiResponse<GetDeductionByIdResponse>?> GetDeductionByIdAsync(string id)
{
var request = new RestRequest($"api/deduction/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetDeductionByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreateDeductionResponse>?> CreateDeductionAsync(CreateDeductionRequest data)
{
var request = new RestRequest("api/deduction", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateDeductionResponse>(_client, request);
}
public async Task<bool> DeleteDeductionByIdAsync(string id)
{
var request = new RestRequest($"api/deduction/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<UpdateDeductionResponse>?> UpdateDeductionAsync(UpdateDeductionRequest data)
{
var request = new RestRequest("api/deduction/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateDeductionResponse>(_client, request);
}
}