Files
blazor-hrm/Features/Organization/Designation/DesignationService.cs
T
2026-07-21 14:08:10 +07:00

54 lines
2.2 KiB
C#

using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Organization.Designation.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Organization.Designation;
public class DesignationService : BaseService
{
private readonly RestClient _client;
public DesignationService(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<GetDesignationListResponse>>?> GetDesignationListAsync()
{
var request = new RestRequest("api/designation", Method.Get);
return await ExecuteWithResponseAsync<List<GetDesignationListResponse>>(_client, request);
}
public async Task<ApiResponse<GetDesignationByIdResponse>?> GetDesignationByIdAsync(string id)
{
var request = new RestRequest($"api/designation/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetDesignationByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreateDesignationResponse>?> CreateDesignationAsync(CreateDesignationRequest data)
{
var request = new RestRequest("api/designation", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateDesignationResponse>(_client, request);
}
public async Task<ApiResponse<UpdateDesignationResponse>?> UpdateDesignationAsync(UpdateDesignationRequest data)
{
var request = new RestRequest("api/designation/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateDesignationResponse>(_client, request);
}
public async Task<bool> DeleteDesignationByIdAsync(string id)
{
var request = new RestRequest($"api/designation/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
}