using System; using System.Linq; using Ultimus.Utilitarios; using ULA.Cathay.CreditoModel.Credito; using System.Data.Entity; using System.Data.Entity.Validation; using ULA.Cathay.CreditoModel.Entidades; namespace ULA.Cathay.CreditoModel.DAL.Credito { public class DesembolsoDatosGeneralesDAL { UltimusLogs logs = new UltimusLogs("DesembolsoDatosGeneralesDAL"); public DesembolsoDatosGenerales InsertarActualizar(DesembolsoDatosGenerales model) { try { using (CreditoContex db = new CreditoContex()) { var exist = db.DesembolsoDatosGenerales.AsNoTracking().Any(c => c.IdSolicitud == model.IdSolicitud); model.ClearVirtualProperties(); if (!exist) { model.IdProceso = EnumProcesos.Desembolso; model.FechaCreacion = DateTime.Now; db.Set(model.GetType()).Add(model); } else { db.Set(model.GetType()).Attach(model); db.Entry(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 DesembolsoDatosGenerales Obtener(int IdSolicitud) { DesembolsoDatosGenerales model = new DesembolsoDatosGenerales(); try { using (CreditoContex db = new CreditoContex()) { model = db.DesembolsoDatosGenerales. Include(c => c.FormasPagos). Include(c => c.TipoFacilidad). Include(c => c.Moneda). Include("DesembolsoFacturas.Moneda"). Include("DesemboloDetalleOrdenCompra.Moneda"). Include("DesembolsoDetalleAdelantosContraContrato"). Where(c => c.IdSolicitud == IdSolicitud).FirstOrDefault(); } } catch (Exception ex) { logs.Error(ex); throw ex; } return model; } } }