142 lines
No EOL
4.9 KiB
C#
142 lines
No EOL
4.9 KiB
C#
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
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 SucursalAPIController : ApiController
|
|
{
|
|
private static Logger logger = LogManager.GetLogger("SucursalAPIController");
|
|
|
|
private string _IDLogger;
|
|
public string IDLogger
|
|
{
|
|
get { return _IDLogger; }
|
|
set { _IDLogger = string.Format("INCIDENT {0}|", value); }
|
|
}
|
|
|
|
#region Sucursal
|
|
|
|
#region ObtenerItems
|
|
[HttpGet]
|
|
public List<Sucursal> ObtenerItems()
|
|
{
|
|
List<Sucursal> listaSucursal = null;
|
|
try
|
|
{
|
|
listaSucursal = new List<Sucursal>();
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
listaSucursal = db.Sucursal.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|
}
|
|
return listaSucursal;
|
|
}
|
|
#endregion
|
|
|
|
#region toggleStateItem
|
|
[HttpPost]
|
|
public string prueba(Sucursal model)
|
|
{
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
Sucursal _model = db.Sucursal.Where(t => t.IdSucursal == model.IdSucursal).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(Sucursal model)
|
|
{
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
Sucursal _model = db.Sucursal.Where(t => t.IdSucursal == model.IdSucursal).FirstOrDefault();
|
|
if (_model != null)
|
|
{
|
|
_model.CodSucursal = model.CodSucursal;
|
|
_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(Sucursal model)
|
|
{
|
|
try
|
|
{
|
|
//no esta insertando
|
|
Sucursal _model = new Sucursal();
|
|
int? Next_id;
|
|
|
|
int idActual;
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
Next_id = db.Sucursal.Max(t => (int?)t.IdSucursal);
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|
_model.IdSucursal = (idActual + 1);
|
|
_model.CodSucursal = model.CodSucursal;
|
|
_model.Descripcion = model.Descripcion;
|
|
_model.Estado = true;
|
|
_model.UsuarioCreador = model.UsuarioCreador;
|
|
_model.FechaCreacion = DateTime.Now;
|
|
db.Sucursal.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
|
|
|
|
}
|
|
} |