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> SetCreateHojaRuta(BE_HojaRutaCreate entidad) { _metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString(); ResultadoTransaccion resultadoTransaccion = new ResultadoTransaccion(_metodoName, _aplicacionName); try { int Indice = 1; List detalle = new List(); 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(), 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() }; //if(entidad.ModalidadTransporte == "Privado") //{ // HojaRuta = new HojaRutaSAP() // { // ARD_PCK_HJRT_DETCollection = new List(), // 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_NOMAGENTRANS = "ARDICORP S.A.C.", // U_ARD_PHR_CODAGENTRANS = "P20136836545", // U_ARD_PHR_RUCAGENTRANS = "20136836545", // U_ARD_PHR_ESTDESP = "Embarcado" // }; //} //else //{ //} HojaRuta.ARD_PCK_HJRT_DETCollection = detalle; var cadena = "ARD_PHR"; var data = await _connectServiceLayer.PostAsync(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); } } } }