117 lines
3.4 KiB
C#
117 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Ultimus.Utilitarios;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using System.Data.Entity;
|
|
using System.Data.Entity.Validation;
|
|
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
public class CertificadosMandatoDAL
|
|
{
|
|
UltimusLogs logs = new UltimusLogs("CertificadosMandatoDAL");
|
|
|
|
public List<CertificadosMandato> Obtener(FormaliacionInformacionAdicional model)
|
|
{
|
|
List<CertificadosMandato> lista;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
lista = db.CertificadosMandato.Where(c => c.IdSolicitud == model.IdSolicitud &&
|
|
model.Incident == c.Incident && c.IdProceso == model.IdProceso).Include(c=>c.Moneda).ToList();
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
|
|
return lista;
|
|
}
|
|
|
|
public CertificadosMandato InsertarActualizar(CertificadosMandato model)
|
|
{
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
var lista_actual = db.CertificadosMandato.AsNoTracking().Where(c => c.IdSolicitud == model.IdSolicitud &&
|
|
model.Incident == c.Incident && c.IdProceso ==model.IdProceso && c.NroCertificado == model.NroCertificado).FirstOrDefault();
|
|
|
|
if (lista_actual == null)
|
|
{
|
|
db.CertificadosMandato.Add(model);
|
|
}
|
|
else
|
|
{
|
|
db.CertificadosMandato.Attach(model);
|
|
db.Entry<CertificadosMandato>(model).State = EntityState.Modified;
|
|
}
|
|
|
|
db.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
public CertificadosMandato Remover(CertificadosMandato model)
|
|
{
|
|
CertificadosMandato actual;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
actual = db.CertificadosMandato.Where(c => c.IdSolicitud == model.IdSolicitud &&
|
|
model.Incident == c.Incident && c.IdProceso == model.IdProceso && c.NroCertificado == model.NroCertificado).FirstOrDefault();
|
|
|
|
if (actual != null)
|
|
{
|
|
db.CertificadosMandato.Remove(actual);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
actual = null;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
}
|
|
}
|