Files
itca_api_sap_wms/Net.Data/ServicesLayer/HR/HRRepository.cs
T

101 lines
3.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Net.Business.Entities;
using Net.Business.Entities.ServicesLayer;
using Net.Business.Entities.ServicesLayer.CreditNotes;
using Net.Business.Entities.ServicesLayer.HR;
using Net.Connection;
using Net.Connection.ServiceLayer;
using Net.CrossCotting;
using Net.Data.HelperData.HojaRuta;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Net.Data.ServicesLayer.HR
{
public class HRRepository : IHRRepository
{
#region Variables Globales
private string _aplicacionName;
private string _metodoName;
private readonly Regex regex = new Regex(@"<(\w+)>.*");
//Services Layer
private readonly ConnectionServiceLayer _connectServiceLayer;
private readonly IConnectionSQL _context;
#endregion
public HRRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
{
_aplicacionName = this.GetType().Name;
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
_context = context;
}
public async Task<BE_ResultadoTransaccion<object>> SetCreateHojaRuta(BE_HojaRutaCreate entidad)
{
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
try
{
int Indice = 1;
List<HojaRutaDetailsEntities> detalle = new List<HojaRutaDetailsEntities>();
entidad.Detalle.ForEach(item =>
{
var data = HelperHojaRuta.Get(Convert.ToInt32(item.CodigoInterno));
var linea = data.FirstOrDefault();
linea.LineId = Indice;
detalle.Add(linea);
Indice++;
});
HojaRutaSAP HojaRuta = new HojaRutaSAP()
{
ARD_PCK_HJRT_DETCollection = new List<HojaRutaDetailsEntities>(),
U_ARD_PHR_PLACA = entidad.PlacaVehiculo,
U_ARD_PHR_TERRI = entidad.Territorio,
U_ARD_PHR_ZONDIS = entidad.Zona,
U_ARD_PHR_FECCRE = entidad.FechaDespacho,
U_ARD_PHR_MODTRANSP = entidad.ModalidadTransporte,
U_ARD_PHR_NOMDESP = entidad.Despachador,
U_ARD_PHR_ESTDESP = "Embarcado",
U_ARD_PHR_RUCAGENTRANS = entidad.AgenciaTransporte,
U_ARD_PHR_LICCON = entidad.LicenciaConductor,
U_MSV_PKH_ORIG = "Y",
U_ARD_PHR_CNTDOC = entidad.Detalle.Count()
};
HojaRuta.ARD_PCK_HJRT_DETCollection = detalle;
var cadena = "ARD_PHR";
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, HojaRuta);
if (!data.Exito)
{
return resultadoTransaccion.GetInformacionResultado(data.Mensaje.ToString(), entidad);
}
return resultadoTransaccion.GetInformacionResultado((int)data.DocEntry, data.DocNum.ToString(), "Se Listo correctamento...!!!", entidad);
}
catch (Exception ex)
{
return resultadoTransaccion.GetInformacionResultado(ex.Message, entidad);
}
}
}
}