97 lines
3.1 KiB
C#
97 lines
3.1 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 DesembolsoDetalleAdelantosContraContratoDAL
|
|
{
|
|
UltimusLogs logs = new UltimusLogs("DesembolsoDetalleAdelantosContraContratoDAL");
|
|
|
|
public DesembolsoDatosGenerales InsertarActualizar(DesembolsoDatosGenerales model)
|
|
{
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
var actuales = db.DesembolsoDetalleAdelantosContraContrato.AsNoTracking().Where(c => c.IdSolicitud == model.IdSolicitud);
|
|
|
|
foreach (var item in model.DesembolsoDetalleAdelantosContraContrato)
|
|
{
|
|
item.ClearVirtualProperties();
|
|
|
|
if (actuales == null || !actuales.Any(c => c.IdAdelanto == item.IdAdelanto))
|
|
{
|
|
item.IdAdelanto = (db.DesembolsoDetalleAdelantosContraContrato.Max(c => (int?)c.IdAdelanto) ?? 0) + 1;
|
|
item.FechaCreacion = DateTime.Now;
|
|
db.Set(item.GetType()).Add(item);
|
|
}
|
|
else
|
|
{
|
|
db.Set(item.GetType()).Attach(item);
|
|
db.Entry(item).State = EntityState.Modified;
|
|
}
|
|
|
|
db.SaveChanges();
|
|
|
|
}
|
|
|
|
|
|
if (actuales != null)
|
|
{
|
|
foreach (var item in actuales)
|
|
{
|
|
item.ClearVirtualProperties();
|
|
|
|
if (!model.DesembolsoDetalleAdelantosContraContrato.Any(c => c.IdAdelanto == item.IdAdelanto))
|
|
{
|
|
db.Set(item.GetType()).Attach(item);
|
|
db.Set(item.GetType()).Remove(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
db.SaveChanges();
|
|
|
|
}
|
|
}
|
|
catch (DbEntityValidationException ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
public List<DesembolsoDetalleAdelantosContraContrato> Obtener(int IdSolicitud)
|
|
{
|
|
List<DesembolsoDetalleAdelantosContraContrato> model = null;
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
model = db.DesembolsoDetalleAdelantosContraContrato.Where(c => c.IdSolicitud == IdSolicitud).ToList();
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
throw ex;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
}
|
|
}
|