164 lines
4.5 KiB
C#
164 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using Ultimus.Interfaces;
|
|
using Ultimus.Utilitarios;
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
|
|
public class ProcesosDAL
|
|
{
|
|
private UltimusLogs logger = new UltimusLogs("ProcesosDAL");
|
|
|
|
#region Obtener
|
|
|
|
public List<Procesos> Obtener()
|
|
{
|
|
List<Procesos> listaProcesos = null;
|
|
|
|
try
|
|
{
|
|
listaProcesos = new List<Procesos>();
|
|
using (CreditoContex db = new CreditoContex())
|
|
listaProcesos = db.Procesos.ToList();
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
return listaProcesos;
|
|
}
|
|
|
|
|
|
public int ObtenerIdProceso(Procesos model)
|
|
{
|
|
int IdprocesoResult = 0;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
|
|
var Proceso = db.Procesos.Where(x => x.NombreProceso == model.NombreProceso).FirstOrDefault();
|
|
|
|
if (Proceso != null)
|
|
IdprocesoResult = Proceso.IdProceso;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
return IdprocesoResult;
|
|
}
|
|
|
|
public Procesos Obtener(string NombreProceso)
|
|
{
|
|
Procesos listaProcesos = null;
|
|
|
|
try
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(NombreProceso)) {
|
|
throw new Exception("El parametro de Proceso debe venir con un valor");
|
|
}
|
|
|
|
|
|
using (CreditoContex db = new CreditoContex())
|
|
listaProcesos = db.Procesos.Where(x => x.NombreProceso.Trim().ToLower() == NombreProceso.Trim().ToLower()).FirstOrDefault();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
return listaProcesos;
|
|
}
|
|
|
|
public Procesos Obtener(int? IdProceso)
|
|
{
|
|
Procesos listaProcesos = null;
|
|
|
|
try
|
|
{
|
|
if (IdProceso != null)
|
|
using (CreditoContex db = new CreditoContex())
|
|
listaProcesos = db.Procesos.Where(x => x.IdProceso == IdProceso).FirstOrDefault();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
throw ex;
|
|
}
|
|
return listaProcesos;
|
|
}
|
|
#endregion
|
|
|
|
#region Actualizar
|
|
|
|
public string Actualizar(Procesos model)
|
|
{
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
Procesos _model = db.Procesos.Where(t => t.IdProceso == model.IdProceso).FirstOrDefault();
|
|
if (_model != null)
|
|
{
|
|
_model.NombreProceso = model.NombreProceso;
|
|
|
|
db.Entry(_model).State = System.Data.Entity.EntityState.Modified;
|
|
db.SaveChanges();
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
#endregion
|
|
|
|
#region Insertar
|
|
|
|
public string Insertar(Procesos model)
|
|
{
|
|
try
|
|
{
|
|
Procesos _model = new Procesos();
|
|
int? Next_id;
|
|
int idActual;
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
Next_id = db.Procesos.Max(t => (int?)t.IdProceso);
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|
_model.IdProceso = (idActual + 1);
|
|
_model.NombreProceso = model.NombreProceso;
|
|
_model.Estado = true;
|
|
db.Procesos.Add(_model);
|
|
db.SaveChanges();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|