using System; using System.Collections.Generic; using System.Linq; using Ultimus.Utilitarios; using ULA.Cathay.CreditoModel.Credito; using ULA.Cathay.CreditoModel.Entidades; using System.Data.Entity; namespace ULA.Cathay.CreditoModel.DAL.Credito { public class FormalizacionConfiguracionDocumentosLegalesDAL { UltimusLogs logs = new UltimusLogs("FormalizacionConfiguracionDocumentosLegalesDAL"); public List ObtenerDocumentos(DatosGeneralesFormalizacion mDatosGeneralesFormalizacion, string NombreEtapa) { List lista = null; ClienteDAL ClienteDal = new ClienteDAL(); Cliente ClientePrincipal; FormalizacionTipoFacilidades Facilidad; EtapasDAL EtapasDal = new EtapasDAL(); Etapas etapas; ProcesosDAL ProcesosDal = new ProcesosDAL(); OfertaDAL OfertaDal = new OfertaDAL(); Oferta oferta; DesembolsoDatosGeneralesDAL DesembolsoDatosGeneralesDal; DesembolsoDatosGenerales DatosDesembolso; try { using (CreditoContex db = new CreditoContex()) { if (mDatosGeneralesFormalizacion.IdProceso == EnumProcesos.Desembolso) { DesembolsoDatosGeneralesDal = new DesembolsoDatosGeneralesDAL(); DatosDesembolso = DesembolsoDatosGeneralesDal.Obtener(mDatosGeneralesFormalizacion.IdSolicitud); oferta = OfertaDal.ObtenerOfertaSolicitud(new Oferta { IdSolicitud = DatosDesembolso.IdSolicitudCredito.Value }); } else oferta = OfertaDal.ObtenerOfertaSolicitud(new Oferta { IdSolicitud = mDatosGeneralesFormalizacion.IdSolicitud }); etapas = EtapasDal.ObtenerEtapa(NombreEtapa, ProcesosDal.Obtener(mDatosGeneralesFormalizacion.IdProceso).NombreProceso); ClientePrincipal = ClienteDal.ObtenerPrincipal(mDatosGeneralesFormalizacion.IdSolicitud); Facilidad = mDatosGeneralesFormalizacion.FormalizacionTipoFacilidades.FirstOrDefault(); string _ValorVariable1 = (oferta.IdTipoCategoria.HasValue ? oferta.IdTipoCategoria.Value.ToString() : null); string _ValorVariable2 = (Facilidad != null ? Facilidad.IdTipoFacilidad.ToString() : null); string _ValorVariable3 = (mDatosGeneralesFormalizacion.EsGarantiaReal == true ? "1" : "0"); lista = (from c in db.FormalizacionConfiguracionDocumentosLegales.Include(c => c.TipoDocumento) where c.IdEtapa == etapas.IdEtapa && c.Habilitado == true && c.EsEspecifico == mDatosGeneralesFormalizacion.EsEspecifico && ( (c.IdVariante == 1 && ((c.ValorVariante == null) || (c.ValorVariante == _ValorVariable1))) || (c.IdVariante == 2 && ((c.ValorVariante == null) || (c.ValorVariante == _ValorVariable2 && mDatosGeneralesFormalizacion.EsEspecifico == true))) || (c.IdVariante == 3 && ((c.ValorVariante == null) || (c.ValorVariante == _ValorVariable3))) ) select c.TipoDocumento).ToList(); if (lista != null && lista.Count > 0) lista = lista.Distinct().ToList(); } } catch (Exception ex) { logs.Error(ex); throw ex; } return lista; } } }