54 lines
2.2 KiB
C#
54 lines
2.2 KiB
C#
using Indotalent.ConfigBackEnd.Interfaces;
|
|
using Indotalent.ConfigFrontEnd.Common;
|
|
using Indotalent.Features.Performance.Promotion.Cqrs;
|
|
using Indotalent.Infrastructure.Authentication.Identity;
|
|
using Indotalent.Shared.Models;
|
|
using Microsoft.AspNetCore.Components;
|
|
using MudBlazor;
|
|
using RestSharp;
|
|
|
|
namespace Indotalent.Features.Performance.Promotion;
|
|
|
|
public class PromotionService : BaseService
|
|
{
|
|
private readonly RestClient _client;
|
|
|
|
public PromotionService(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<GetPromotionListResponse>>?> GetPromotionListAsync()
|
|
{
|
|
var request = new RestRequest("api/performance-promotion", Method.Get);
|
|
return await ExecuteWithResponseAsync<List<GetPromotionListResponse>>(_client, request);
|
|
}
|
|
|
|
public async Task<ApiResponse<GetPromotionByIdResponse>?> GetPromotionByIdAsync(string id)
|
|
{
|
|
var request = new RestRequest($"api/performance-promotion/{id}", Method.Get);
|
|
return await ExecuteWithResponseAsync<GetPromotionByIdResponse>(_client, request);
|
|
}
|
|
|
|
public async Task<ApiResponse<CreatePromotionResponse>?> CreatePromotionAsync(CreatePromotionRequest data)
|
|
{
|
|
var request = new RestRequest("api/performance-promotion", Method.Post);
|
|
request.AddJsonBody(data);
|
|
return await ExecuteWithResponseAsync<CreatePromotionResponse>(_client, request);
|
|
}
|
|
|
|
public async Task<bool> DeletePromotionByIdAsync(string id)
|
|
{
|
|
var request = new RestRequest($"api/performance-promotion/delete/{id}", Method.Post);
|
|
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
|
return response?.IsSuccess ?? false;
|
|
}
|
|
|
|
public async Task<ApiResponse<UpdatePromotionResponse>?> UpdatePromotionAsync(UpdatePromotionRequest data)
|
|
{
|
|
var request = new RestRequest("api/performance-promotion/update", Method.Post);
|
|
request.AddJsonBody(data);
|
|
return await ExecuteWithResponseAsync<UpdatePromotionResponse>(_client, request);
|
|
}
|
|
} |