78 lines
3.4 KiB
C#
78 lines
3.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Net.Business.Entities;
|
|
using Net.Business.Entities.ServicesLayer;
|
|
using Net.Connection;
|
|
using Net.Connection.ServiceLayer;
|
|
using Net.Constantes;
|
|
using Net.CrossCotting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Net.Data.ServicesLayer
|
|
{
|
|
public class BusinessPartnersRepository : IBusinessPartnersRepository
|
|
{
|
|
#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 BusinessPartnersRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
|
{
|
|
_aplicacionName = this.GetType().Name;
|
|
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
|
_context = context;
|
|
}
|
|
|
|
|
|
public async Task<BE_ResultadoTransaccion<BE_BusinessPartners>> GetBusinessPartnersByFilter(FE_BusinessPartners entidad)
|
|
{
|
|
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
|
|
|
ResultadoTransaccion<BE_BusinessPartners> resultadoTransaccion = new ResultadoTransaccion<BE_BusinessPartners>(_metodoName, _aplicacionName);
|
|
|
|
try
|
|
{
|
|
string select = "select= CardCode, CardName,CardType, FederalTaxID,Address,EmailAddress,Phone1";
|
|
|
|
entidad.CardCode = string.IsNullOrEmpty(entidad.CardCode) ? string.Empty : entidad.CardCode;
|
|
entidad.CardName = string.IsNullOrEmpty(entidad.CardName) ? string.Empty : entidad.CardName;
|
|
entidad.FederalTaxID = string.IsNullOrEmpty(entidad.FederalTaxID) ? string.Empty : entidad.FederalTaxID;
|
|
|
|
string cadena = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(entidad.CardCode))
|
|
{
|
|
cadena = string.Format("{0}?$filter = Valid eq 'tYES' and CardCode eq '{1}' &${2}", StoreProcedure.SP_SERVICES_LAYER_BUSINESSPARTNERS, entidad.CardCode, select);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(entidad.CardName))
|
|
{
|
|
cadena = string.Format("{0}?$filter = Valid eq 'tYES' and CardName eq '{1}' &${2}", StoreProcedure.SP_SERVICES_LAYER_BUSINESSPARTNERS, entidad.CardName, select);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(entidad.FederalTaxID))
|
|
{
|
|
cadena = string.Format("{0}?$filter = Valid eq 'tYES' and FederalTaxID eq '{1}' &${2}", StoreProcedure.SP_SERVICES_LAYER_BUSINESSPARTNERS, entidad.FederalTaxID, select);
|
|
}
|
|
|
|
int maxpagesize = 0;
|
|
List<BE_BusinessPartners> objectList = await _connectServiceLayer.GetAsync<BE_BusinessPartners>(cadena, maxpagesize);
|
|
|
|
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
|
}
|
|
}
|
|
}
|
|
} |