284 lines
10 KiB
C#
284 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using Ultimus.Interfaces;
|
|
using Ultimus.Utilitarios;
|
|
using System.Data.Entity;
|
|
using System.Data.Entity.Validation;
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
public class ClienteDAL
|
|
{
|
|
private UltimusLogs logger = new UltimusLogs("ClienteDAL");
|
|
|
|
/// <summary>
|
|
/// Consultar información del cliente por el ID del Cliente
|
|
/// </summary>
|
|
/// <param name="Idcliente">Secuencia de la tabla cliente</param>
|
|
/// <returns>Listado de los cliente cuya Id cliente sea igual al parametro de entrada</returns>
|
|
public Cliente Obtener(int Idcliente)
|
|
{
|
|
Cliente listaCliente = new Cliente();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
listaCliente = (db.Cliente
|
|
.Where(x => x.IdCliente == Idcliente)
|
|
.Include(e => e.TipoIdentificacion)
|
|
.Include(e => e.TipoFuenteIngreso)
|
|
.Include(e => e.TipoTramite)
|
|
.Include(e => e.ClasificacionCliente)
|
|
.Include(e => e.TipoCliente)
|
|
.Include(e => e.Ejecutivo)).FirstOrDefault();
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
return listaCliente;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Consultar información del cliente por la Identificación
|
|
/// </summary>
|
|
/// <param name="Identificacion">Identificación Cédula, Passaporte o RUC para juridico</param>
|
|
/// <returns>Listado de los cliente cuya identificación sea igual a la identificación del parametro de entrada</returns>
|
|
public List<Cliente> Obtener(string Identificacion, string codigoBP = null)
|
|
{
|
|
List<Cliente> listaCliente = new List<Cliente>();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
listaCliente = (db.Cliente
|
|
.Where(x => (string.IsNullOrEmpty(Identificacion) || x.NumeroIdentificacion == Identificacion)||
|
|
(string.IsNullOrEmpty(codigoBP) || x.CodigoBP == codigoBP))
|
|
.Include(e => e.TipoIdentificacion)
|
|
.Include(e => e.TipoFuenteIngreso)
|
|
.Include(e => e.TipoTramite)
|
|
.Include(e => e.ClasificacionCliente)
|
|
.Include(e => e.TipoCliente)
|
|
.Include(e => e.Ejecutivo)).ToList();
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
return listaCliente;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Consultar información del cliente por el ID de la solicitud
|
|
/// </summary>
|
|
/// <param name="IdSolicitud">Secuencia de la tabla Solicitud</param>
|
|
/// <returns>Obtiene el cliente principal de la solicitud</returns>
|
|
public Cliente ObtenerPrincipal(int IdSolicitud)
|
|
{
|
|
Cliente listaCliente = new Cliente();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
var solicitante = db.Solicitante.Where(c => c.IdSolicitud == IdSolicitud && c.EsPrincipal == true)
|
|
.Include("Cliente.TipoIdentificacion")
|
|
.Include("Cliente.TipoFuenteIngreso")
|
|
.Include("Cliente.TipoTramite")
|
|
.Include("Cliente.ClasificacionCliente")
|
|
.Include("Cliente.TipoCliente")
|
|
.Include("Cliente.Ejecutivo")
|
|
.Include("Cliente.EmailCliente")
|
|
.FirstOrDefault();
|
|
|
|
listaCliente = solicitante == null ? null : solicitante.Cliente;
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
return listaCliente;
|
|
}
|
|
|
|
public List<Cliente> ObtenerListaCliente(int IdSolicitud)
|
|
{
|
|
List<Cliente> listaCliente = new List<Cliente>();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
var solicitante = db.Solicitante.Where(c => c.IdSolicitud == IdSolicitud)
|
|
.Include("Cliente.TipoIdentificacion")
|
|
.Include("Cliente.TipoFuenteIngreso")
|
|
.Include("Cliente.TipoTramite")
|
|
.Include("Cliente.ClasificacionCliente")
|
|
.Include("Cliente.TipoCliente")
|
|
.Include("Cliente.Ejecutivo")
|
|
.Include("Cliente.EmailCliente")
|
|
.ToList();
|
|
|
|
foreach(var a in solicitante)
|
|
{
|
|
if(a!= null && a.Cliente != null)
|
|
listaCliente.Add(a.Cliente);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
return listaCliente;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Actualizar o insertar registo en la tabla cliente
|
|
/// </summary>
|
|
/// <param name="model">Objeto cliente con la información relacionada ala cliente.</param>
|
|
/// <returns></returns>
|
|
public BaseJson InsertarActualizar(Cliente model)
|
|
{
|
|
BaseJson ValorRetorno = new BaseJson();
|
|
Cliente actual = new Cliente();
|
|
|
|
try
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
model = InsertarActualizarCliente(model);
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
actual = null;
|
|
}
|
|
return ValorRetorno;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Actualizar o insertar registo en la tabla cliente
|
|
/// </summary>
|
|
/// <param name="model">Objeto cliente con la información relacionada ala cliente.</param>
|
|
/// <returns></returns>
|
|
public Cliente InsertarActualizarCliente(Cliente model)
|
|
{
|
|
Cliente actual = new Cliente();
|
|
|
|
try
|
|
{
|
|
model.TipoIdentificacion = null;
|
|
model.TipoFuenteIngreso = null;
|
|
model.TipoTramite = null;
|
|
model.ClasificacionCliente = null;
|
|
model.TipoCliente = null;
|
|
model.Ejecutivo = null;
|
|
model.Solicitante = new HashSet<Solicitante>();
|
|
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
actual = Conn.Cliente.Where(x => x.IdCliente == model.IdCliente).FirstOrDefault();
|
|
if (actual == null)
|
|
{
|
|
int? Next_id = Conn.Cliente.Max(t => (int?)t.IdCliente);
|
|
model.IdCliente = (Next_id == null) ? 1 : Next_id.Value + 1;
|
|
model.FechaCreacion = DateTime.Now;
|
|
Conn.Cliente.Add(model);
|
|
}
|
|
else
|
|
{
|
|
model.FechaModificacion = DateTime.Now;
|
|
model.UsuarioModificado = model.UsuarioCreador;
|
|
model.FechaCreacion = actual.FechaCreacion;
|
|
model.UsuarioCreador = actual.UsuarioCreador;
|
|
Conn.Entry(actual).State = EntityState.Detached;
|
|
Conn.Cliente.Attach(model);
|
|
Conn.Entry(model).State = EntityState.Modified;
|
|
}
|
|
Conn.SaveChanges();
|
|
model = Obtener(model.IdCliente);
|
|
}
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
actual = null;
|
|
}
|
|
return model;
|
|
}
|
|
|
|
public Cliente ObtenerPrincipalSimple(int IdSolicitud)
|
|
{
|
|
Cliente listaCliente = new Cliente();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
var solicitante = db.Solicitante
|
|
.Include("Cliente")
|
|
.AsNoTracking()
|
|
.FirstOrDefault(c => c.IdSolicitud == IdSolicitud && c.EsPrincipal == true);
|
|
|
|
listaCliente = solicitante == null ? null : solicitante.Cliente;
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
return listaCliente;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|