140 lines
5.2 KiB
C#
140 lines
5.2 KiB
C#
|
|
using NLog;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Data.Entity;
|
|||
|
|
using System.Web;
|
|||
|
|
using System.Web.Http;
|
|||
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|||
|
|
using ULA.Cathay.ModuloMantenimiento.Commons;
|
|||
|
|
using ULA.Cathay.ModuloMantenimiento.Json;
|
|||
|
|
using Ultimus.Interfaces;
|
|||
|
|
|
|||
|
|
namespace ULA.Cathay.ModuloMantenimiento.ControllersWebApi
|
|||
|
|
{
|
|||
|
|
public class CondicionesGeneralesCreditoAPIController : ApiController
|
|||
|
|
{
|
|||
|
|
private static Logger logger = LogManager.GetLogger("CondicionesGeneralesCreditoAPIController");
|
|||
|
|
|
|||
|
|
private string _IDLogger;
|
|||
|
|
public string IDLogger
|
|||
|
|
{
|
|||
|
|
get { return _IDLogger; }
|
|||
|
|
set { _IDLogger = string.Format("INCIDENT {0}|", value); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region CondicionesGeneralesCredito
|
|||
|
|
|
|||
|
|
#region ObtenerItems
|
|||
|
|
[HttpGet]
|
|||
|
|
public List<CondicionesGeneralesCredito> ObtenerItems()
|
|||
|
|
{
|
|||
|
|
List<CondicionesGeneralesCredito> ListaCondicionesGeneralesCredito = new List<CondicionesGeneralesCredito>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
ListaCondicionesGeneralesCredito = db.CondicionesGeneralesCredito.Include(x => x.TipoCondicion).ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return ListaCondicionesGeneralesCredito;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region toggleStateItem
|
|||
|
|
[HttpPost]
|
|||
|
|
public string toggleStateItem(CondicionesGeneralesCredito model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
CondicionesGeneralesCredito _model = db.CondicionesGeneralesCredito.Where(t => t.IdCondicion == model.IdCondicion).FirstOrDefault();
|
|||
|
|
if (_model != null)
|
|||
|
|
{
|
|||
|
|
_model.Habilitado = model.Habilitado;
|
|||
|
|
_model.UsuarioModificado = model.UsuarioModificado;
|
|||
|
|
_model.FechaModificacion = DateTime.Now;
|
|||
|
|
db.SaveChanges();
|
|||
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|||
|
|
}
|
|||
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region ModificarItem
|
|||
|
|
[HttpPost]
|
|||
|
|
public string ModificarItem(CondicionesGeneralesCredito model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
CondicionesGeneralesCredito _model = db.CondicionesGeneralesCredito.Where(t => t.IdCondicion == model.IdCondicion).FirstOrDefault();
|
|||
|
|
if (_model != null)
|
|||
|
|
{
|
|||
|
|
_model.Descripcion = model.Descripcion;
|
|||
|
|
_model.UsuarioModificado = model.UsuarioModificado;
|
|||
|
|
_model.FechaModificacion = DateTime.Now;
|
|||
|
|
db.SaveChanges();
|
|||
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|||
|
|
}
|
|||
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region InsertarItem
|
|||
|
|
[HttpPost]
|
|||
|
|
public string InsertarItem(CondicionesGeneralesCredito model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
CondicionesGeneralesCredito _model = new CondicionesGeneralesCredito();
|
|||
|
|
int? Next_id;
|
|||
|
|
int idActual;
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
Next_id = db.CondicionesGeneralesCredito.Max(t => (int?)t.IdCondicion);
|
|||
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|||
|
|
_model.IdCondicion = (idActual + 1);
|
|||
|
|
_model.IdTipoCondicion = model.IdTipoCondicion;
|
|||
|
|
_model.Descripcion = model.Descripcion;
|
|||
|
|
_model.Habilitado = true;
|
|||
|
|
_model.UsuarioCreador = model.UsuarioCreador;
|
|||
|
|
_model.FechaCreacion = DateTime.Now;
|
|||
|
|
db.CondicionesGeneralesCredito.Add(_model);
|
|||
|
|
db.SaveChanges();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|||
|
|
}
|
|||
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|