131 lines
No EOL
4.4 KiB
C#
131 lines
No EOL
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 ProfesionAPIController : ApiController
|
|
{
|
|
private static Logger logger = LogManager.GetLogger("ProfesionAPIController");
|
|
|
|
private string _IDLogger;
|
|
public string IDLogger
|
|
{
|
|
get { return _IDLogger; }
|
|
set { _IDLogger = string.Format("INCIDENT {0}|", value); }
|
|
}
|
|
|
|
#region Profesion
|
|
#region ObtenerItems
|
|
[HttpGet]
|
|
public List<Profesion> ObtenerItems()
|
|
{
|
|
List<Profesion> lista = null;
|
|
try
|
|
{
|
|
lista = new List<Profesion>();
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
lista = db.Profesion.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|
}
|
|
return lista;
|
|
}
|
|
#endregion
|
|
|
|
#region toggleStateItem
|
|
[HttpPost]
|
|
public string toggleStateItem(Profesion model)
|
|
{
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
Profesion _model = db.Profesion.Where(t => t.IdProfesion == model.IdProfesion).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(Profesion model)
|
|
{
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
Profesion _model = db.Profesion.Where(t => t.IdProfesion == model.IdProfesion).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 InsertarItem
|
|
[HttpPost]
|
|
public string InsertarItem(Profesion model)
|
|
{
|
|
try
|
|
{
|
|
Profesion _model = new Profesion();
|
|
int? Next_id;
|
|
int idActual;
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
Next_id = db.Profesion.Max(t => int.Parse(t.IdProfesion));
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|
_model.IdProfesion = (idActual + 1).ToString();
|
|
_model.Descripcion = model.Descripcion;
|
|
_model.Estado = true;
|
|
db.Profesion.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
|
|
}
|
|
} |