452 lines
19 KiB
C#
452 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using Ultimus.Utilitarios;
|
|
using Ultimus.Interfaces;
|
|
using System.Data.Entity;
|
|
using System.Data.Entity.Validation;
|
|
using EntityFramework.Extensions;
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
public class GrupoInteresEconomicoDAL
|
|
{
|
|
UltimusLogs logs = new UltimusLogs("GrupoInteresEconomicoDAL");
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="IdentificacionPrincipal"></param>
|
|
/// <returns></returns>
|
|
public List<GrupoInteresEconomico> Obtener(string IdentificacionPrincipal)
|
|
{
|
|
List<GrupoInteresEconomico> ObjRetorno = new List<GrupoInteresEconomico>();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
ObjRetorno = (from q in Conn.GrupoInteresEconomico
|
|
.Include(e => e.GrupoInteresEconomicoDetalle)
|
|
.Include("GrupoInteresEconomicoDetalle.IncisoSugef")
|
|
where (from w in Conn.GrupoInteresEconomicoMiembros
|
|
where w.IdentificacionPrincipal == IdentificacionPrincipal
|
|
select w.IdentificacionAsociado).ToList().Contains(q.Identificacion)
|
|
select q).AsNoTracking().ToList();
|
|
}
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
|
|
return ObjRetorno;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="IdentificacionPrincipal"></param>
|
|
/// <returns></returns>
|
|
public GrupoInteresEconomicoDetalle ObtenerGrupoInteresEconomicoDetalle(GrupoInteresEconomicoDetalle modelo)
|
|
{
|
|
GrupoInteresEconomicoDetalle ObjRetorno = new GrupoInteresEconomicoDetalle();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
ObjRetorno = (from q in Conn.GrupoInteresEconomicoDetalle
|
|
.Include(e => e.GrupoInteresEconomico)
|
|
.Include(e => e.IncisoSugef)
|
|
where q.Identificacion == modelo.Identificacion && q.OperacionLinea == modelo.OperacionLinea
|
|
select q).AsNoTracking().FirstOrDefault();
|
|
}
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
|
|
return ObjRetorno;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="IdentificacionPrincipal"></param>
|
|
/// <returns></returns>
|
|
public List<GrupoInteresEconomicoDetalle> ObtenerListaGrupoInteresEconomicoDetalle(GrupoInteresEconomicoDetalle modelo)
|
|
{
|
|
List<GrupoInteresEconomicoDetalle> ObjRetorno = new List<GrupoInteresEconomicoDetalle>();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
ObjRetorno = (from q in Conn.GrupoInteresEconomicoDetalle
|
|
.Include(e => e.GrupoInteresEconomico)
|
|
.Include(e => e.IncisoSugef)
|
|
where q.Identificacion == modelo.Identificacion
|
|
select q).AsNoTracking().ToList();
|
|
}
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
|
|
return ObjRetorno;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="modelo"></param>
|
|
/// <returns></returns>
|
|
public BaseJson InsertarActualizar(GrupoInteresEconomico modelo, bool ActualizarGie = false)
|
|
{
|
|
GrupoInteresEconomico ModeloActual = new GrupoInteresEconomico();
|
|
GrupoInteresEconomicoDetalle ModeloActualDetalle = new GrupoInteresEconomicoDetalle();
|
|
GrupoInteresEconomico modeloAuxiliar = new GrupoInteresEconomico();
|
|
BaseJson ValorRetorno = new BaseJson();
|
|
int? Secuencia;
|
|
|
|
try
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
|
|
modeloAuxiliar.CopyValueProperties(modelo);
|
|
|
|
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
#region GrupoInteresEconomico
|
|
|
|
modelo.ClearVirtualProperties();
|
|
|
|
ModeloActual = (Conn.GrupoInteresEconomico.Where(q => q.Identificacion == modelo.Identificacion)).AsNoTracking().FirstOrDefault();
|
|
|
|
if (ModeloActual == null)
|
|
{
|
|
modelo.FechaCreacion = DateTime.Now;
|
|
Conn.GrupoInteresEconomico.Add(modelo);
|
|
}
|
|
else
|
|
{
|
|
modelo.FechaModificacion = DateTime.Now;
|
|
modelo.UsuarioModificado = modelo.UsuarioCreador;
|
|
modelo.FechaCreacion = ModeloActual.FechaCreacion;
|
|
modelo.UsuarioCreador = ModeloActual.UsuarioCreador;
|
|
modelo.Process = modelo.Process;
|
|
modelo.Step = modelo.Step;
|
|
modelo.Incident = modelo.Incident;
|
|
|
|
if (!string.IsNullOrWhiteSpace(ModeloActual.CodigoBPSap) && string.IsNullOrWhiteSpace(modelo.CodigoBPSap))
|
|
modelo.CopyValueProperties(ModeloActual);
|
|
|
|
Conn.Entry(ModeloActual).State = System.Data.Entity.EntityState.Detached;
|
|
Conn.GrupoInteresEconomico.Attach(modelo);
|
|
Conn.Entry(modelo).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
|
|
Conn.SaveChanges();
|
|
|
|
#endregion
|
|
|
|
#region GrupoInteresEconomicoDetalle
|
|
|
|
if (modeloAuxiliar.GrupoInteresEconomicoDetalle != null)
|
|
{
|
|
foreach (GrupoInteresEconomicoDetalle Detalle in modeloAuxiliar.GrupoInteresEconomicoDetalle)
|
|
{
|
|
Detalle.ClearVirtualProperties();
|
|
|
|
if (Detalle.TipoOperacion == "0")
|
|
ModeloActualDetalle = (Conn.GrupoInteresEconomicoDetalle.Where(q => q.Identificacion == Detalle.Identificacion && q.OperacionLinea == Detalle.OperacionLinea && q.Incident == Detalle.Incident)).AsNoTracking().FirstOrDefault();
|
|
else
|
|
ModeloActualDetalle = (Conn.GrupoInteresEconomicoDetalle.Where(q => q.Identificacion == Detalle.Identificacion && q.OperacionLinea == Detalle.OperacionLinea)).AsNoTracking().FirstOrDefault();
|
|
|
|
if (ModeloActualDetalle == null)
|
|
{
|
|
if (!Detalle.EsSap.Value && (string.IsNullOrEmpty(Detalle.OperacionLinea) || string.IsNullOrWhiteSpace(Detalle.OperacionLinea)))
|
|
{
|
|
List<GrupoInteresEconomicoDetalle> ListaGrupoInteresEconomicoDetalle = Conn.GrupoInteresEconomicoDetalle.Where(q => q.Identificacion == Detalle.Identificacion && q.EsSap == false).AsNoTracking().ToList();
|
|
if (ListaGrupoInteresEconomicoDetalle == null || ListaGrupoInteresEconomicoDetalle.Count == 0)
|
|
Secuencia = 0;
|
|
else
|
|
Secuencia = ListaGrupoInteresEconomicoDetalle.Max(x => Convert.ToInt32(x.OperacionLinea));
|
|
Detalle.OperacionLinea = (Secuencia + 1).ToString();
|
|
}
|
|
Detalle.FechaCreacion = DateTime.Now;
|
|
Conn.GrupoInteresEconomicoDetalle.Add(Detalle);
|
|
}
|
|
else
|
|
{
|
|
if (ModeloActualDetalle.EsSap == true && ActualizarGie == false)
|
|
{
|
|
Detalle.DescTipoGarantia = string.IsNullOrEmpty(ModeloActualDetalle.DescTipoGarantia) ? Detalle.DescTipoGarantia : ModeloActualDetalle.DescTipoGarantia;
|
|
Detalle.TipoGarantia = string.IsNullOrEmpty(ModeloActualDetalle.TipoGarantia) ? Detalle.TipoGarantia : ModeloActualDetalle.TipoGarantia;
|
|
Detalle.CodigoIncisoSUGEF = ModeloActualDetalle.CodigoIncisoSUGEF == null ? Detalle.CodigoIncisoSUGEF : ModeloActualDetalle.CodigoIncisoSUGEF;
|
|
}
|
|
|
|
Detalle.FechaModificacion = DateTime.Now;
|
|
Detalle.UsuarioModificado = Detalle.UsuarioCreador;
|
|
Detalle.FechaCreacion = ModeloActualDetalle.FechaCreacion;
|
|
Detalle.UsuarioCreador = ModeloActualDetalle.UsuarioCreador;
|
|
Detalle.Process = modelo.Process;
|
|
Detalle.Step = modelo.Step;
|
|
Detalle.Incident = modelo.Incident;
|
|
|
|
Conn.Entry(ModeloActualDetalle).State = System.Data.Entity.EntityState.Detached;
|
|
Conn.GrupoInteresEconomicoDetalle.Attach(Detalle);
|
|
Conn.Entry(Detalle).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
|
|
Conn.SaveChanges();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
modelo.GrupoInteresEconomicoDetalle = modeloAuxiliar.GrupoInteresEconomicoDetalle;
|
|
modelo.GrupoInteresEconomicoMiembros = modeloAuxiliar.GrupoInteresEconomicoMiembros;
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
ModeloActual = null;
|
|
ModeloActualDetalle = null;
|
|
}
|
|
return ValorRetorno;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="modelo"></param>
|
|
/// <returns></returns>
|
|
public BaseJson InsertarActualizarMiembros(GrupoInteresEconomicoMiembros modelo)
|
|
{
|
|
GrupoInteresEconomicoMiembros ModeloActual = new GrupoInteresEconomicoMiembros();
|
|
BaseJson ValorRetorno = new BaseJson();
|
|
|
|
try
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
ModeloActual = (Conn.GrupoInteresEconomicoMiembros.Where(q => q.IdentificacionPrincipal == modelo.IdentificacionPrincipal && q.IdentificacionAsociado == modelo.IdentificacionAsociado)).AsNoTracking().FirstOrDefault();
|
|
if (ModeloActual == null)
|
|
{
|
|
modelo.FechaCreacion = DateTime.Now;
|
|
Conn.GrupoInteresEconomicoMiembros.Add(modelo);
|
|
}
|
|
else
|
|
{
|
|
modelo.FechaModificacion = DateTime.Now;
|
|
modelo.UsuarioModificado = modelo.UsuarioCreador;
|
|
modelo.FechaCreacion = ModeloActual.FechaCreacion;
|
|
modelo.UsuarioCreador = ModeloActual.UsuarioCreador;
|
|
|
|
Conn.Entry(ModeloActual).State = System.Data.Entity.EntityState.Detached;
|
|
Conn.GrupoInteresEconomicoMiembros.Attach(modelo);
|
|
Conn.Entry(modelo).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
Conn.SaveChanges();
|
|
}
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
ModeloActual = null;
|
|
}
|
|
return ValorRetorno;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="modelo"></param>
|
|
/// <returns></returns>
|
|
public BaseJson EliminarMiembros(GrupoInteresEconomicoMiembros modelo)
|
|
{
|
|
GrupoInteresEconomicoMiembros ModeloActualMiembros = new GrupoInteresEconomicoMiembros();
|
|
List<GrupoInteresEconomicoDetalle> ListaGrupoInteresDetalle = new List<GrupoInteresEconomicoDetalle>();
|
|
BaseJson ValorRetorno = new BaseJson();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
string Asociado = modelo.IdentificacionAsociado;
|
|
int? Incidente = modelo.Incident;
|
|
ListaGrupoInteresDetalle = Conn.GrupoInteresEconomicoDetalle.Where(x => x.Identificacion == Asociado && x.Incident == Incidente).ToList();
|
|
Conn.GrupoInteresEconomicoDetalle.RemoveRange(ListaGrupoInteresDetalle);
|
|
Conn.SaveChanges();
|
|
ModeloActualMiembros = Conn.GrupoInteresEconomicoMiembros.Where(x => x.IdentificacionAsociado == modelo.IdentificacionAsociado && x.IdentificacionPrincipal == modelo.IdentificacionPrincipal).FirstOrDefault();
|
|
Conn.GrupoInteresEconomicoMiembros.Remove(ModeloActualMiembros);
|
|
Conn.SaveChanges();
|
|
}
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
ModeloActualMiembros = null;
|
|
ListaGrupoInteresDetalle = null;
|
|
}
|
|
return ValorRetorno;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="modelo"></param>
|
|
/// <returns></returns>
|
|
public BaseJson EliminarGIEDetalle(GrupoInteresEconomicoDetalle modelo)
|
|
{
|
|
GrupoInteresEconomicoDetalle ModeloActual = new GrupoInteresEconomicoDetalle();
|
|
BaseJson ValorRetorno = new BaseJson();
|
|
|
|
try
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
if (modelo.TipoOperacion == "0")
|
|
ModeloActual = Conn.GrupoInteresEconomicoDetalle.Where(q => q.Identificacion == modelo.Identificacion
|
|
&& q.OperacionLinea == modelo.OperacionLinea
|
|
&& q.Incident == modelo.GrupoInteresEconomico.Incident).FirstOrDefault();
|
|
else
|
|
ModeloActual = Conn.GrupoInteresEconomicoDetalle.Where(q => q.Identificacion == modelo.Identificacion
|
|
&& q.OperacionLinea == modelo.OperacionLinea).FirstOrDefault();
|
|
if (ModeloActual != null)
|
|
{
|
|
Conn.GrupoInteresEconomicoDetalle.Remove(ModeloActual);
|
|
Conn.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
ModeloActual = null;
|
|
}
|
|
return ValorRetorno;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="IdSolicitud"></param>
|
|
/// <param name="CodigoTipoGie"></param>
|
|
/// <param name="DescTipoGie"></param>
|
|
/// <returns></returns>
|
|
public BaseJson ActualizarTipoGIEMiembros(int IdSolicitud, string CodigoTipoGie, string DescTipoGie)
|
|
{
|
|
GrupoInteresEconomicoMiembros ModeloActual = new GrupoInteresEconomicoMiembros();
|
|
ClienteDAL ConnCliente = new ClienteDAL();
|
|
Cliente ObjCliente = new Cliente();
|
|
BaseJson ValorRetorno = new BaseJson();
|
|
|
|
try
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
ObjCliente = ConnCliente.ObtenerPrincipal(IdSolicitud);
|
|
using (CreditoContex Conn = new CreditoContex())
|
|
{
|
|
(from q in Conn.GrupoInteresEconomico.Include(e => e.GrupoInteresEconomicoDetalle)
|
|
where (from w in Conn.GrupoInteresEconomicoMiembros
|
|
where w.IdentificacionPrincipal == ObjCliente.NumeroIdentificacion
|
|
select w.IdentificacionAsociado).ToList().Contains(q.Identificacion)
|
|
select q).Update(t => new GrupoInteresEconomico { CodTipoGie = CodigoTipoGie, DescTipoGie = DescTipoGie });
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException ex1)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
ModeloActual = null;
|
|
ObjCliente = null;
|
|
ConnCliente = null;
|
|
}
|
|
return ValorRetorno;
|
|
}
|
|
|
|
}
|
|
}
|