161 lines
5.7 KiB
C#
161 lines
5.7 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 AgenteSeguroAPIController : ApiController
|
|||
|
|
{
|
|||
|
|
private static Logger logger = LogManager.GetLogger("AgenteSeguroAPIController");
|
|||
|
|
|
|||
|
|
private string _IDLogger;
|
|||
|
|
public string IDLogger
|
|||
|
|
{
|
|||
|
|
get { return _IDLogger; }
|
|||
|
|
set { _IDLogger = string.Format("INCIDENT {0}|", value); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region AgenteSeguro
|
|||
|
|
#region ObtenerItems
|
|||
|
|
[HttpGet]
|
|||
|
|
public List<AgenteSeguro> ObtenerItems()
|
|||
|
|
{
|
|||
|
|
List<AgenteSeguro> lista = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
lista = new List<AgenteSeguro>();
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
lista = db.AgenteSeguro.Include("Aseguradora").ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
}
|
|||
|
|
return lista;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region toggleStateItem
|
|||
|
|
[HttpPost]
|
|||
|
|
public string toggleStateItem(AgenteSeguro model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
AgenteSeguro _model = db.AgenteSeguro.Where(t => t.IdAgenteSeguro == model.IdAgenteSeguro).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(AgenteSeguro model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
AgenteSeguro _model = db.AgenteSeguro.Where(t => t.IdAgenteSeguro == model.IdAgenteSeguro).FirstOrDefault();
|
|||
|
|
if (_model != null)
|
|||
|
|
{
|
|||
|
|
_model.IdAseguradora = model.IdAseguradora;
|
|||
|
|
_model.NombreCompleto = model.NombreCompleto;
|
|||
|
|
_model.Email = model.Email;
|
|||
|
|
_model.Telefono = model.Telefono;
|
|||
|
|
_model.Direccion = model.Direccion;
|
|||
|
|
_model.NumLicencia = model.NumLicencia;
|
|||
|
|
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(AgenteSeguro model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
AgenteSeguro _model = new AgenteSeguro();
|
|||
|
|
int? Next_id;
|
|||
|
|
int idActual;
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
Next_id = db.AgenteSeguro.Max(t => (int?)t.IdAgenteSeguro);
|
|||
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|||
|
|
_model.IdAgenteSeguro = (idActual + 1);
|
|||
|
|
_model.IdAseguradora = model.IdAseguradora;
|
|||
|
|
_model.NombreCompleto = model.NombreCompleto;
|
|||
|
|
_model.Email = model.Email;
|
|||
|
|
_model.Telefono = model.Telefono;
|
|||
|
|
_model.Direccion = model.Direccion;
|
|||
|
|
_model.NumLicencia = model.NumLicencia;
|
|||
|
|
_model.Estado = true;
|
|||
|
|
db.AgenteSeguro.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<Aseguradora> ObtenerItemsAseguradora()
|
|||
|
|
{
|
|||
|
|
List<Aseguradora> lista = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
lista = new List<Aseguradora>();
|
|||
|
|
using (PrendarioContext db = new PrendarioContext())
|
|||
|
|
{
|
|||
|
|
lista = db.Aseguradora.ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
logger.Error(IDLogger + " Error " + Utilities.GetCurrentMethodName() + "=" + ex.Message + ex.StackTrace);
|
|||
|
|
}
|
|||
|
|
return lista;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|