246 lines
No EOL
9 KiB
C#
246 lines
No EOL
9 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 System.Data.Entity.Validation;
|
|
using System.Data.Entity;
|
|
using ULA.Davivienda.ModuloMantenimiento.Commons;
|
|
|
|
namespace ULA.Davivienda.ModuloMantenimiento.ControllersWebApi
|
|
{
|
|
public class CuentaAgenciaAPIController : ApiController
|
|
{
|
|
private static Logger logger = LogManager.GetLogger("CuentaAgenciaAPIController");
|
|
|
|
private string _IDLogger;
|
|
public string IDLogger
|
|
{
|
|
get { return _IDLogger; }
|
|
set { _IDLogger = string.Format("INCIDENT {0}|", value); }
|
|
}
|
|
|
|
#region CuentaAgencia
|
|
#region ObtenerItems
|
|
[HttpGet]
|
|
public List<CuentaAgencia> ObtenerItems()
|
|
{
|
|
List<CuentaAgencia> lista = null;
|
|
try
|
|
{
|
|
lista = new List<CuentaAgencia>();
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
lista = db.CuentaAgencia.Include(x => x.Moneda).Include(x => x.TipoFuncionalidadCuenta).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|
}
|
|
return lista;
|
|
}
|
|
#endregion
|
|
|
|
#region toggleStateItem
|
|
[HttpPost]
|
|
public string toggleStateItem(CuentaAgencia model)
|
|
{
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
CuentaAgencia _model = db.CuentaAgencia.Where(t => t.IdCuentaAgencia == model.IdCuentaAgencia).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 ModificarItem
|
|
[HttpPost]
|
|
public string ModificarItem(CuentaAgencia model)
|
|
{
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
CuentaAgencia _model = db.CuentaAgencia.Where(t => t.IdCuentaAgencia == model.IdCuentaAgencia).FirstOrDefault();
|
|
if (_model != null)
|
|
{
|
|
_model.NumCuenta = model.NumCuenta;
|
|
_model.TipoCuenta = model.TipoCuenta;
|
|
_model.IdMoneda = model.IdMoneda;
|
|
_model.Descripcion = model.Descripcion;
|
|
_model.IdTipoFuncionalidadCuenta = model.IdTipoFuncionalidadCuenta;// Steven Rojas
|
|
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(CuentaAgencia model)
|
|
{
|
|
try
|
|
{
|
|
CuentaAgencia _model = new CuentaAgencia();
|
|
int? Next_id;
|
|
int idActual;
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
Next_id = db.CuentaAgencia.Max(t => (int?)t.IdCuentaAgencia);
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|
_model.IdCuentaAgencia = (idActual + 1);
|
|
_model.IdMoneda = model.IdMoneda;
|
|
_model.NumCuenta = model.NumCuenta;
|
|
_model.TipoCuenta = model.TipoCuenta;
|
|
_model.Descripcion = model.Descripcion;
|
|
_model.Estado = true;
|
|
_model.IdTipoFuncionalidadCuenta = model.IdTipoFuncionalidadCuenta; // Steven Rojas
|
|
db.CuentaAgencia.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
|
|
|
|
#region ObtenerItems
|
|
[HttpGet]
|
|
public List<AgenciaVehiculo> ObtenerItemsAgenciaVehiculo()
|
|
{
|
|
List<AgenciaVehiculo> lista = null;
|
|
try
|
|
{
|
|
lista = new List<AgenciaVehiculo>();
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
lista = db.AgenciaVehiculo.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|
}
|
|
return lista;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region ObtenerItemsMoneda
|
|
[HttpGet]
|
|
public List<Moneda> ObtenerItemsMoneda()
|
|
{
|
|
List<Moneda> lista = null;
|
|
try
|
|
{
|
|
lista = new List<Moneda>();
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
lista = db.Moneda.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|
}
|
|
return lista;
|
|
}
|
|
#endregion
|
|
|
|
#region ObtenerItemsTipoFuncionalidad
|
|
[HttpGet]
|
|
public List<TipoFuncionalidadCuenta> ObtenerItemsTipoFuncionalidad()
|
|
{
|
|
List<TipoFuncionalidadCuenta> lista = null;
|
|
try
|
|
{
|
|
lista = new List<TipoFuncionalidadCuenta>();
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
lista = db.TipoFuncionalidadCuenta.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|
}
|
|
return lista;
|
|
}
|
|
#endregion
|
|
|
|
#region ValidarTipoFuncionalidad
|
|
[HttpPost]
|
|
public string ValidarTipoFuncionalidad(CuentaAgencia model) // Steven Rojas
|
|
{
|
|
try
|
|
{
|
|
if (model.IdTipoFuncionalidadCuenta == 1) // Si se va a modificar a "Sin Definir"
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
int cuentasMoneda = db.CuentaAgencia.Count(t => t.IdMoneda == model.IdMoneda);
|
|
if (cuentasMoneda > 1)
|
|
{
|
|
CuentaAgencia _model = db.CuentaAgencia.Where(t => t.IdMoneda == model.IdMoneda && t.IdTipoFuncionalidadCuenta != 1 && t.IdCuentaAgencia != model.IdCuentaAgencia).FirstOrDefault();
|
|
if (_model != null)
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
else
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
else if (cuentasMoneda == 1 && model.IdCuentaAgencia == 0)
|
|
{
|
|
CuentaAgencia _model = db.CuentaAgencia.Where(t => t.IdMoneda == model.IdMoneda && t.IdTipoFuncionalidadCuenta != 1).FirstOrDefault();
|
|
if (_model != null)
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
else
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
else
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
} |