60 lines
2.4 KiB
C#
60 lines
2.4 KiB
C#
using Indotalent.ConfigBackEnd.Interfaces;
|
|
using Indotalent.ConfigFrontEnd.Common;
|
|
using Indotalent.Features.Thirdparty.CustomerCategory.Cqrs;
|
|
using Indotalent.Infrastructure.Authentication.Identity;
|
|
using Indotalent.Shared.Models;
|
|
using Microsoft.AspNetCore.Components;
|
|
using MudBlazor;
|
|
using RestSharp;
|
|
|
|
namespace Indotalent.Features.Thirdparty.CustomerCategory;
|
|
|
|
public class CustomerCategoryService : BaseService
|
|
{
|
|
private readonly RestClient _client;
|
|
|
|
public CustomerCategoryService(
|
|
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<GetCustomerCategoryListResponse>>?> GetCustomerCategoryListAsync()
|
|
{
|
|
var request = new RestRequest("api/customer-category", Method.Get);
|
|
return await ExecuteWithResponseAsync<List<GetCustomerCategoryListResponse>>(_client, request);
|
|
}
|
|
|
|
public async Task<ApiResponse<GetCustomerCategoryByIdResponse>?> GetCustomerCategoryByIdAsync(string id)
|
|
{
|
|
var request = new RestRequest($"api/customer-category/{id}", Method.Get);
|
|
return await ExecuteWithResponseAsync<GetCustomerCategoryByIdResponse>(_client, request);
|
|
}
|
|
|
|
public async Task<ApiResponse<CreateCustomerCategoryResponse>?> CreateCustomerCategoryAsync(CreateCustomerCategoryRequest data)
|
|
{
|
|
var request = new RestRequest("api/customer-category", Method.Post);
|
|
request.AddJsonBody(data);
|
|
return await ExecuteWithResponseAsync<CreateCustomerCategoryResponse>(_client, request);
|
|
}
|
|
|
|
public async Task<bool> DeleteCustomerCategoryByIdAsync(string id)
|
|
{
|
|
var request = new RestRequest($"api/customer-category/delete/{id}", Method.Post);
|
|
|
|
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
|
return response?.IsSuccess ?? false;
|
|
}
|
|
|
|
public async Task<ApiResponse<UpdateCustomerCategoryResponse>?> UpdateCustomerCategoryAsync(UpdateCustomerCategoryRequest data)
|
|
{
|
|
var request = new RestRequest("api/customer-category/update", Method.Post);
|
|
request.AddJsonBody(data);
|
|
return await ExecuteWithResponseAsync<UpdateCustomerCategoryResponse>(_client, request);
|
|
}
|
|
} |