149 lines
5.7 KiB
C#
149 lines
5.7 KiB
C#
|
|
using NLog;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Web;
|
|||
|
|
using System.Web.Http;
|
|||
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|||
|
|
using ULA.Cathay.ModuloMantenimiento.Commons;
|
|||
|
|
using Ultimus.Interfaces;
|
|||
|
|
|
|||
|
|
namespace ULA.Cathay.ModuloMantenimiento.ControllersWebApi
|
|||
|
|
{
|
|||
|
|
public class SectorAPIController : ApiController
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
private static Logger logger = LogManager.GetLogger("SectorAPIController");
|
|||
|
|
|
|||
|
|
private string _IDLogger;
|
|||
|
|
public string IDLogger
|
|||
|
|
{
|
|||
|
|
get { return _IDLogger; }
|
|||
|
|
set { _IDLogger = string.Format("INCIDENT {0}|", value); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region ObtenerItems
|
|||
|
|
[HttpGet]
|
|||
|
|
public List<Sector> ObtenerItems()
|
|||
|
|
{
|
|||
|
|
List<Sector> listaTipoFacilidad = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
listaTipoFacilidad = new List<Sector>();
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
listaTipoFacilidad = db.Sector.ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
}
|
|||
|
|
return listaTipoFacilidad;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region toggleStateItem
|
|||
|
|
[HttpPost]
|
|||
|
|
public string toggleStateItem(Sector model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
Sector _model = db.Sector.Where(t => t.IdSector == model.IdSector).FirstOrDefault();
|
|||
|
|
if (_model != null)
|
|||
|
|
{
|
|||
|
|
_model.Estado = model.Estado;
|
|||
|
|
_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(Sector model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
Sector _model = db.Sector.Where(t => t.IdSector == model.IdSector).FirstOrDefault();
|
|||
|
|
if (_model != null)
|
|||
|
|
{
|
|||
|
|
_model.Descripcion = model.Descripcion;
|
|||
|
|
_model.PersonalPromedio = model.PersonalPromedio;
|
|||
|
|
_model.VentasAnualesNetas = model.VentasAnualesNetas;
|
|||
|
|
_model.ValorActivosTotales = model.ValorActivosTotales;
|
|||
|
|
_model.PorcentajePersonalPromedio = model.PorcentajePersonalPromedio;
|
|||
|
|
_model.PorcentajeVentasAnualesNetas = model.PorcentajeVentasAnualesNetas;
|
|||
|
|
_model.PorcentajeValorActivosTotales = model.PorcentajeValorActivosTotales;
|
|||
|
|
_model.Porcentaje = model.Porcentaje;
|
|||
|
|
_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(Sector model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Sector _model = new Sector();
|
|||
|
|
int? Next_id;
|
|||
|
|
int idActual;
|
|||
|
|
using (CreditoContex db = new CreditoContex())
|
|||
|
|
{
|
|||
|
|
Next_id = db.Sector.Max(t => (int?)t.IdSector);
|
|||
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|||
|
|
_model.IdSector = (idActual + 1);
|
|||
|
|
_model.Descripcion = model.Descripcion;
|
|||
|
|
_model.PersonalPromedio = model.PersonalPromedio;
|
|||
|
|
_model.VentasAnualesNetas = model.VentasAnualesNetas;
|
|||
|
|
_model.ValorActivosTotales = model.ValorActivosTotales;
|
|||
|
|
_model.PorcentajePersonalPromedio = model.PorcentajePersonalPromedio;
|
|||
|
|
_model.PorcentajeVentasAnualesNetas = model.PorcentajeVentasAnualesNetas;
|
|||
|
|
_model.PorcentajeValorActivosTotales = model.PorcentajeValorActivosTotales;
|
|||
|
|
_model.Porcentaje = model.Porcentaje;
|
|||
|
|
_model.Estado = true;
|
|||
|
|
_model.UsuarioCreador = model.UsuarioCreador;
|
|||
|
|
_model.FechaCreacion = DateTime.Now;
|
|||
|
|
db.Sector.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
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|