130 lines
4.8 KiB
C#
130 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Ultimus.Utilitarios;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using System.Data.Entity;
|
|
using Ultimus.Interfaces;
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
public class ParticipantesLegalesAdicionalesDAL
|
|
{
|
|
UltimusLogs logs = new UltimusLogs("ParticipantesLegalesAdicionalesDAL");
|
|
|
|
public List<ParticipantesLegalesAdicionales> Obtener(int IdSolicitud)
|
|
{
|
|
|
|
List<ParticipantesLegalesAdicionales> model = null;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
model = db.ParticipantesLegalesAdicionales.Include(c => c.TipoRolCredito).Where(c => c.IdSolicitud == IdSolicitud).ToList();
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo para obtener la lista de representantes del deudor en el documento de carta de condiciones en base al tipo rol (sobrecarga de public List<ParticipantesLegalesAdicionales> Obtener(int IdSolicitud))
|
|
/// </summary>
|
|
/// <param name="IdSolicitud">ID de solicitud de la oferta</param>
|
|
/// <param name="IdTipoRol">ID del tipo de rol</param>
|
|
/// <returns>Se devuelve una lista de ParticipantesLegalesAdicionales</returns>
|
|
public List<ParticipantesLegalesAdicionales> Obtener(int IdSolicitud, int IdTipoRol)
|
|
{
|
|
List<ParticipantesLegalesAdicionales> model = null;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
model = db.ParticipantesLegalesAdicionales.Include(c => c.TipoRolCredito).Where(c => (c.IdSolicitud == IdSolicitud && c.IdTipoRol == IdTipoRol)).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
return model;
|
|
}
|
|
|
|
public string ActualizarInsertar(List<ParticipantesLegalesAdicionales> lista)
|
|
{
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
if (lista == null || lista.Count == 0)
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
|
|
int IdSolcitud = lista.FirstOrDefault().IdSolicitud;
|
|
|
|
var Actual = db.ParticipantesLegalesAdicionales.AsNoTracking().Where(c => c.IdSolicitud == IdSolcitud).ToList();
|
|
|
|
foreach (var item in lista)
|
|
{
|
|
item.TipoRolCredito = null;
|
|
item.Solicitud = null;
|
|
|
|
if (item.Fecha == null)
|
|
{
|
|
item.Fecha = DateTime.Now;
|
|
db.ParticipantesLegalesAdicionales.Add(item);
|
|
}
|
|
else
|
|
{
|
|
db.ParticipantesLegalesAdicionales.Attach(item);
|
|
db.Entry<ParticipantesLegalesAdicionales>(item).State = EntityState.Modified;
|
|
}
|
|
}
|
|
|
|
db.SaveChanges();
|
|
|
|
foreach (var item in Actual)
|
|
{
|
|
if (!lista.Where(c => c.IdTipoRol == item.IdTipoRol && c.CodigoBP == item.CodigoBP).Any())
|
|
{
|
|
db.ParticipantesLegalesAdicionales.Attach(item);
|
|
db.ParticipantesLegalesAdicionales.Remove(item);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
|
|
public BaseJson EliminarParticipante(ParticipantesLegalesAdicionales model)
|
|
{
|
|
BaseJson respuesta = new BaseJson();
|
|
try
|
|
{
|
|
using (CreditoContex dataContex = new CreditoContex())
|
|
{
|
|
List<ParticipantesLegalesAdicionales> lista = dataContex.ParticipantesLegalesAdicionales.Where(x => x.IdSolicitud == model.IdSolicitud && x.CodigoBP == model.CodigoBP && x.IdTipoRol == model.IdTipoRol).ToList();
|
|
dataContex.ParticipantesLegalesAdicionales.RemoveRange(lista);
|
|
dataContex.SaveChanges();
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
return respuesta;
|
|
}
|
|
}
|
|
}
|