130 lines
4.4 KiB
C#
130 lines
4.4 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Web;
|
|||
|
|
using System.Web.Http;
|
|||
|
|
using ULA.Davivienda.ModuloMantenimiento.Json;
|
|||
|
|
using ULA.Davivienda.ModuloMantenimiento;
|
|||
|
|
using ULA.Davivienda.PrendarioModel;
|
|||
|
|
using ULA.Davivienda.PrendarioModel.Prendario;
|
|||
|
|
using NLog;
|
|||
|
|
using ULA.Davivienda.ModuloMantenimiento.Commons;
|
|||
|
|
|
|||
|
|
namespace ULA.Davivienda.ModuloMantenimiento.ControllersWebApi
|
|||
|
|
{
|
|||
|
|
public class MonedaAPIController : ApiController
|
|||
|
|
{
|
|||
|
|
private static Logger logger = LogManager.GetLogger("MonedaAPIController");
|
|||
|
|
|
|||
|
|
private string _IDLogger;
|
|||
|
|
public string IDLogger
|
|||
|
|
{
|
|||
|
|
get { return _IDLogger; }
|
|||
|
|
set { _IDLogger = string.Format("INCIDENT {0}|", value); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region Moneda
|
|||
|
|
#region ObtenerItemsMoneda
|
|||
|
|
[HttpGet]
|
|||
|
|
public List<Moneda> ObtenerItemsMoneda()
|
|||
|
|
{
|
|||
|
|
List<Moneda> listaMoneda = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
listaMoneda = new List<Moneda>();
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
listaMoneda = db.Moneda.ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
}
|
|||
|
|
return listaMoneda;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region toggleStateItemMoneda
|
|||
|
|
[HttpPost]
|
|||
|
|
public string toggleStateItemMoneda(Moneda model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
Moneda _model = db.Moneda.Where(t => t.IdMoneda == model.IdMoneda).FirstOrDefault();
|
|||
|
|
if (_model != null)
|
|||
|
|
{
|
|||
|
|
_model.Estado = model.Estado;
|
|||
|
|
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 ModificarItemMoneda
|
|||
|
|
[HttpPost]
|
|||
|
|
public string ModificarItemMoneda(Moneda model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
Moneda _model = db.Moneda.Where(t => t.IdMoneda == model.IdMoneda).FirstOrDefault();
|
|||
|
|
if (_model != null)
|
|||
|
|
{
|
|||
|
|
_model.Descripcion = model.Descripcion;
|
|||
|
|
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 InsertarItemMoneda
|
|||
|
|
[HttpPost]
|
|||
|
|
public string InsertarItemMoneda(Moneda model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Moneda _model = new Moneda();
|
|||
|
|
int? Next_id;
|
|||
|
|
int idActual;
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
Next_id = db.Moneda.Max(t => (int?)t.IdMoneda);
|
|||
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|||
|
|
_model.IdMoneda = (idActual + 1);
|
|||
|
|
_model.Descripcion = model.Descripcion;
|
|||
|
|
_model.Estado = true;
|
|||
|
|
db.Moneda.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
|
|||
|
|
}
|
|||
|
|
}
|