2025-06-24 16:02:27 -04:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Shared.DTO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
namespace DAS
|
2025-06-24 14:46:32 -04:00
|
|
|
|
{
|
|
|
|
|
public class RegistrarMedicion
|
|
|
|
|
{
|
2025-06-24 16:02:27 -04:00
|
|
|
|
private readonly HttpClient _httpClient;
|
|
|
|
|
private readonly IConfiguration _configuration;
|
2025-06-25 08:39:23 -04:00
|
|
|
|
private static string? password;
|
|
|
|
|
private static string? rutEmpresa;
|
|
|
|
|
private static string? rutUsuario;
|
2025-06-24 16:02:27 -04:00
|
|
|
|
|
|
|
|
|
public RegistrarMedicion(HttpClient httpClient, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
_configuration = configuration;
|
2025-06-25 08:39:23 -04:00
|
|
|
|
rutUsuario = _configuration["Credenciales:rutEmpresa"] ?? "";
|
|
|
|
|
rutEmpresa = _configuration["Credenciales:rutUsuario"] ?? "" ?? "";
|
|
|
|
|
password = _configuration["Credenciales:password"] ?? "";
|
2025-06-24 16:02:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> EnviarMedicionAsync(string codigoObra, MedicionSubterraneaRequest request)
|
|
|
|
|
{
|
2025-06-25 08:39:23 -04:00
|
|
|
|
|
|
|
|
|
request.Autenticacion.Password = password;
|
|
|
|
|
request.Autenticacion.RutEmpresa = rutEmpresa;
|
|
|
|
|
request.Autenticacion.RutUsuario = rutUsuario;
|
|
|
|
|
|
2025-06-24 16:02:27 -04:00
|
|
|
|
var baseUrl = _configuration["ApiSubterranea:BaseUrl"];
|
|
|
|
|
var endpoint = _configuration["ApiSubterranea:Endpoint"];
|
|
|
|
|
var url = $"{baseUrl}{endpoint}";
|
|
|
|
|
|
|
|
|
|
var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss-0000");
|
|
|
|
|
|
|
|
|
|
var json = JsonSerializer.Serialize(request);
|
|
|
|
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
|
|
|
|
|
|
content.Headers.Add("codigoObra", codigoObra);
|
|
|
|
|
content.Headers.Add("timeStampOrigen", timeStamp);
|
2025-06-24 14:46:32 -04:00
|
|
|
|
|
2025-06-24 16:02:27 -04:00
|
|
|
|
var response = await _httpClient.PostAsync(url, content);
|
2025-06-24 14:46:32 -04:00
|
|
|
|
|
2025-06-24 16:02:27 -04:00
|
|
|
|
return response.IsSuccessStatusCode;
|
|
|
|
|
}
|
2025-06-24 14:46:32 -04:00
|
|
|
|
}
|
|
|
|
|
}
|