64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Components.Authorization;
|
|
using OrdersManagement.Models;
|
|
using SytelineSaAppEfDataModel.Dtos;
|
|
|
|
namespace OrdersManagement.Services
|
|
{
|
|
public class EdiCustomerOrderService(IHttpClientFactory httpClientFactory, AuthenticationStateProvider authenticationStateProvider, ErrorLogService errorLogService) : ServiceBase<EdiCustomerOrderDto>(httpClientFactory, authenticationStateProvider)
|
|
{
|
|
public async Task<IEnumerable<EdiCustomerOrderDto>?> GetEdiCustomerOrdersAsync()
|
|
{
|
|
try
|
|
{
|
|
return await GetListAsync("api/EdiCustomerOrders");
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
Console.WriteLine($"Błąd HTTP w GetEdiCustomerOrdersAsync: {ex.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<EdiCustomerOrderDto?> GetEdiCustomerOrderAsync(Guid customerOrderNumber)
|
|
{
|
|
try
|
|
{
|
|
return await GetByIdAsync($"api/EdiCustomerOrders/by-order-number/?customerOrderNumber={customerOrderNumber}");
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
Console.WriteLine($"Błąd HTTP w GetEdiCustomerOrdersAsync: {ex.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<ResponseModel?> SendOrderToSyteline(Guid customerOrderNumber, string orderNumber)
|
|
{
|
|
try
|
|
{
|
|
HttpResponseMessage responseMessage = await PostAsync($"api/EdiCustomerOrders/send-to-syteline?customerOrderNumber={customerOrderNumber}");
|
|
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
return new ResponseModel(1, orderNumber, null, null);
|
|
}
|
|
|
|
string? errorMessage = null;
|
|
IEnumerable<ErrorLogDto>? logs = await errorLogService.GetErrorLogsAsync(customerOrderNumber);
|
|
|
|
if (logs != null)
|
|
{
|
|
errorMessage = string.Join("\r\n", logs.Select(x => x.ErrMsg));
|
|
}
|
|
|
|
return new ResponseModel(0, orderNumber, errorMessage, null);
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
Console.WriteLine($"Błąd HTTP w GetEdiCustomerOrdersAsync: {ex.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|