158 lines
No EOL
5.3 KiB
C#
158 lines
No EOL
5.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity.Validation;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
using ULA.Davivienda.PrendarioModel;
|
|
using ULA.Davivienda.PrendarioModel.Prendario;
|
|
using ULA.Davivienda.PrestamoAutos.Commons;
|
|
using ULA.Davivienda.PrestamoAutos.CotizadorServiceLayer;
|
|
using ULA.Davivienda.PrestamoAutos.Json;
|
|
using ULA.Davivienda.PrestamoAutos.WCFPrendarioSeguros;
|
|
using Ultimus.Utilitarios;
|
|
|
|
namespace ULA.Davivienda.PrestamoAutos.ControllersWebApi
|
|
{
|
|
public class BeneficiarioAPIController : ApiController
|
|
{
|
|
|
|
Crypt crypt = new Crypt();
|
|
LogFile log = new LogFile();
|
|
|
|
|
|
#region ObtenerBeneficiarioSeguroSolicitud
|
|
[HttpGet]
|
|
public List<BeneficiarioSeguro> ObtenerBeneficiarioSeguroSolicitud(int? IdSolicitud = null)
|
|
{
|
|
List<BeneficiarioSeguro> resp = null;
|
|
try
|
|
{
|
|
resp = new List<BeneficiarioSeguro>();
|
|
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
resp = db.BeneficiarioSeguro
|
|
.Include(e => e.RubroSeguro)
|
|
.Where( y => y.IdSolicitud == IdSolicitud)
|
|
.ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return resp;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region InsertarBeneficiarioSeguroSolicitud
|
|
[HttpPost]
|
|
public string InsertarBeneficiarioSeguroSolicitud(BeneficiarioSeguro _model)
|
|
{
|
|
int? Next_id = null;
|
|
int idActual = 0;
|
|
|
|
try
|
|
{
|
|
|
|
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
|
|
int nCantBenef = db.BeneficiarioSeguro.Where(e => e.IdSolicitud == _model.IdSolicitud).Count();
|
|
RubroSeguro rubro = db.RubroSeguro.Where(q => q.IdRubroSeguro == _model.IdRubroSeguro).FirstOrDefault();
|
|
if (rubro == null)
|
|
{
|
|
return "Rubro no encontrado";
|
|
}
|
|
|
|
if (rubro.IdAseguradora == EnumAseguradora.INS && nCantBenef == 2)
|
|
{
|
|
return "Estimado usuario ha registrado el número máximo de beneficiarios permitido";
|
|
}
|
|
else if (rubro.IdAseguradora == EnumAseguradora.DS && nCantBenef == 5)
|
|
{
|
|
return "Estimado usuario ha registrado el número máximo de beneficiarios permitido";
|
|
}
|
|
|
|
|
|
decimal sumPorcentaje = 0;
|
|
|
|
try
|
|
{
|
|
sumPorcentaje = db.BeneficiarioSeguro.Where(e => e.IdSolicitud == _model.IdSolicitud).Sum(e => e.Porcentaje).Value;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
sumPorcentaje = 0;
|
|
}
|
|
|
|
|
|
|
|
if ((sumPorcentaje + (decimal)_model.Porcentaje) > 100)
|
|
{
|
|
return "Estimado usuario el porcentaje supera la distribución del 100%. No es posible registrar un porcentaje adicional del " + _model.Porcentaje.ToString() + "%";
|
|
}
|
|
|
|
|
|
|
|
|
|
Next_id = db.BeneficiarioSeguro.Max(t => (int?)t.IdBeneficiarioSeguro);
|
|
idActual = (Next_id == null) ? 0 : Convert.ToInt32(Next_id);
|
|
|
|
|
|
_model.IdBeneficiarioSeguro = (idActual + 1);
|
|
db.BeneficiarioSeguro.Add(_model);
|
|
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region EliminarBeneficiarioSeguroSolicitud
|
|
[HttpPost]
|
|
public string EliminarBeneficiarioSeguroSolicitud(BeneficiarioSeguro _model)
|
|
{
|
|
BeneficiarioSeguro _modelDel = null;
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
_modelDel = db.BeneficiarioSeguro.Where(p => p.IdBeneficiarioSeguro == _model.IdBeneficiarioSeguro).FirstOrDefault();
|
|
|
|
if (_modelDel != null)
|
|
db.BeneficiarioSeguro.Remove(_modelDel);
|
|
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
|
|
return TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
|
|
return TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
} |