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

146 lines
5.9 KiB
C#
Raw Normal View History

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()
};
//if(entidad.ModalidadTransporte == "Privado")
//{
// 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_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<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);
}
}
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> UpdateCreateCreditNotes(dynamic entidad, int DocEntry)
{
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
try
{
//var cadena = "Drafts";
var cadena = $"CreditNotes({DocEntry})";
var data = await _connectServiceLayer.PatchAsyncSBA<BE_BaseResponseSap>(cadena, entidad);
if (!data.Exito)
{
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
}
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
}
catch (Exception ex)
{
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
}
}
}
}