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>?> GetPromotionListAsync() { var request = new RestRequest("api/performance-promotion", Method.Get); return await ExecuteWithResponseAsync>(_client, request); } public async Task?> GetPromotionByIdAsync(string id) { var request = new RestRequest($"api/performance-promotion/{id}", Method.Get); return await ExecuteWithResponseAsync(_client, request); } public async Task?> CreatePromotionAsync(CreatePromotionRequest data) { var request = new RestRequest("api/performance-promotion", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } public async Task DeletePromotionByIdAsync(string id) { var request = new RestRequest($"api/performance-promotion/delete/{id}", Method.Post); var response = await ExecuteWithResponseAsync(_client, request); return response?.IsSuccess ?? false; } public async Task?> UpdatePromotionAsync(UpdatePromotionRequest data) { var request = new RestRequest("api/performance-promotion/update", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } }