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>?> GetDeductionListAsync() { var request = new RestRequest("api/deduction", Method.Get); return await ExecuteWithResponseAsync>(_client, request); } public async Task?> GetDeductionByIdAsync(string id) { var request = new RestRequest($"api/deduction/{id}", Method.Get); return await ExecuteWithResponseAsync(_client, request); } public async Task?> CreateDeductionAsync(CreateDeductionRequest data) { var request = new RestRequest("api/deduction", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } public async Task DeleteDeductionByIdAsync(string id) { var request = new RestRequest($"api/deduction/delete/{id}", Method.Post); var response = await ExecuteWithResponseAsync(_client, request); return response?.IsSuccess ?? false; } public async Task?> UpdateDeductionAsync(UpdateDeductionRequest data) { var request = new RestRequest("api/deduction/update", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } }