207 lines
8.2 KiB
C#
207 lines
8.2 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;
|
|
using ULA.Cathay.CreditoModel.CorporativoDatosRecientes;
|
|
using ULA.Cathay.CreditoModel.DAL.CorporativoDatosRecientes;
|
|
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
public class FormalizacionDocumentosLegalesDAL
|
|
{
|
|
UltimusLogs logs = new UltimusLogs("FormalizacionDocumentosLegalesDAL");
|
|
|
|
public List<FormalizacionDocumentosLegales> Obtener(int Incident, int IdSolicitud)
|
|
{
|
|
|
|
List<FormalizacionDocumentosLegales> lista = null;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
lista = db.FormalizacionDocumentosLegales
|
|
.Where(c => c.Incident == Incident && c.IdSolicitud == IdSolicitud)
|
|
.Include(c => c.ClasificacionDocumentosAdjuntos)
|
|
.Include(c => c.TipoDocumento)
|
|
.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
return lista;
|
|
}
|
|
|
|
public BaseJson GenerarDocumentos(DatosGeneralesFormalizacion mDatosGeneralesFormalizacion, string NombreEtapa)
|
|
{
|
|
BaseJson resp = new BaseJson();
|
|
List<TipoDocumento> lista = null;
|
|
|
|
FormalizacionConfiguracionDocumentosLegalesDAL FormalizacionConfiguracionDocumentosLegalesDal = new FormalizacionConfiguracionDocumentosLegalesDAL();
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
lista = FormalizacionConfiguracionDocumentosLegalesDal.ObtenerDocumentos(mDatosGeneralesFormalizacion, NombreEtapa);
|
|
|
|
if (lista != null && lista.Count > 0)
|
|
foreach (var item in lista)
|
|
{
|
|
FormalizacionDocumentosLegales documentos = new FormalizacionDocumentosLegales();
|
|
|
|
documentos.IdSolicitud = mDatosGeneralesFormalizacion.IdSolicitud;
|
|
documentos.IdProceso = mDatosGeneralesFormalizacion.IdProceso;
|
|
documentos.Incident = mDatosGeneralesFormalizacion.Incident;
|
|
documentos.IdTipoDocumento = item.IdTipoDocumento;
|
|
documentos.FechaCreacion = DateTime.Now;
|
|
|
|
db.FormalizacionDocumentosLegales.Add(documentos);
|
|
|
|
}
|
|
|
|
db.SaveChanges();
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
throw ex;
|
|
}
|
|
return resp;
|
|
}
|
|
|
|
public FormalizacionDocumentosLegales ObtenerDocumento(int IdSolicitud,int IncidenteFormalizacion, int IdTipoDocumento)
|
|
{
|
|
FormalizacionDocumentosLegales resp = null;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
resp = db.FormalizacionDocumentosLegales.Include(c => c.TipoDocumento)
|
|
.Where(c => c.Incident == IncidenteFormalizacion && c.IdTipoDocumento == IdTipoDocumento && c.IdSolicitud == IdSolicitud)
|
|
.FirstOrDefault();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
return resp;
|
|
}
|
|
|
|
public List <FormalizacionDocumentosLegales> ObtenerDocumentos(int IdSolicitud, int IncidenteFormalizacion, int IdTipoDocumento)
|
|
{
|
|
List<FormalizacionDocumentosLegales> resp = null;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
resp = db.FormalizacionDocumentosLegales.Include(c => c.TipoDocumento)
|
|
.Where(c => c.Incident == IncidenteFormalizacion && c.IdTipoDocumento == IdTipoDocumento && c.IdSolicitud == IdSolicitud)
|
|
.OrderByDescending(x => x.CodDocumentoAdjunto).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
return resp;
|
|
}
|
|
|
|
public FormalizacionDocumentosLegales ActualizarDocumento(FormalizacionDocumentosLegales model)
|
|
{
|
|
ClienteDAL ClienteDal = new ClienteDAL();
|
|
Cliente cliente = null;
|
|
ClasificacionDocumentosAdjuntosDAL ClasificacionDocumentosAdjuntosDal=new ClasificacionDocumentosAdjuntosDAL();
|
|
ClasificacionDocumentosAdjuntos ClasificacionDocumentosAdjunto=null;
|
|
ClienteDocumentosDAL ObjClienteDocumentosDal = new ClienteDocumentosDAL();
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
model.ClasificacionDocumentosAdjuntos = null;
|
|
db.FormalizacionDocumentosLegales.Attach(model);
|
|
db.Entry<FormalizacionDocumentosLegales>(model).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
|
|
ClasificacionDocumentosAdjunto=model.CodDocumentoAdjunto.HasValue?ClasificacionDocumentosAdjuntosDal.Obtener(model.CodDocumentoAdjunto.Value):null;
|
|
|
|
ClienteDocumentos ObjClienteDocumentos = new ClienteDocumentos();
|
|
cliente = ClienteDal.ObtenerPrincipal(model.IdSolicitud);
|
|
|
|
ObjClienteDocumentos.NumeroIdentificacion = cliente.NumeroIdentificacion;
|
|
ObjClienteDocumentos.IdTipoDocumento = model.IdTipoDocumento;
|
|
ObjClienteDocumentos.FechaVencimiento = null;
|
|
ObjClienteDocumentos.FechaSolicitarCliente =null;
|
|
ObjClienteDocumentos.FechaClienteEntregoInformacion = model.FechaClienteEntregoInformacion;
|
|
ObjClienteDocumentos.CodDocumentoAdjunto = model.CodDocumentoAdjunto;
|
|
ObjClienteDocumentos.RutaFisicaAdjunto = ClasificacionDocumentosAdjunto == null ? null : ClasificacionDocumentosAdjunto.RutaFisica;
|
|
|
|
ObjClienteDocumentosDal.GuardarActualizar(ObjClienteDocumentos);
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
return model;
|
|
}
|
|
|
|
public ICollection<FormalizacionDocumentosLegales> ActualizarDocumentos(ICollection<FormalizacionDocumentosLegales> lista)
|
|
{
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
|
|
foreach (var model in lista)
|
|
{
|
|
model.ClasificacionDocumentosAdjuntos = null;
|
|
db.FormalizacionDocumentosLegales.Attach(model);
|
|
db.Entry<FormalizacionDocumentosLegales>(model).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
return lista;
|
|
}
|
|
|
|
public void EliminarDoclegales(int IdSolicitud,int IncidenteFormalizacion)
|
|
{
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
List<FormalizacionDocumentosLegales> documentos = db.FormalizacionDocumentosLegales.Where(x => x.IdSolicitud == IdSolicitud && x.Incident == IncidenteFormalizacion).ToList();
|
|
db.FormalizacionDocumentosLegales.RemoveRange(documentos);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|