63 lines
2 KiB
C#
63 lines
2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using Ultimus.Interfaces;
|
|
using Ultimus.Utilitarios;
|
|
using System.Data.Entity.Validation;
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
public class ContactoDAL
|
|
{
|
|
private UltimusLogs logger = new UltimusLogs("ContactoDAL");
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public BaseJson InsertarActualizar(Contacto model)
|
|
{
|
|
BaseJson ValorRetorno = new BaseJson();
|
|
Contacto actual = new Contacto();
|
|
|
|
try
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
actual = db.Contacto.Where(x => x.IdContacto == model.IdContacto).FirstOrDefault();
|
|
|
|
if (actual == null)
|
|
{
|
|
int? Next_id = db.Cliente.Max(t => (int?)t.IdCliente);
|
|
model.IdContacto = (Next_id == null) ? 1 : Next_id.Value + 1;
|
|
db.Contacto.Add(model);
|
|
}
|
|
else
|
|
{
|
|
db.Entry(actual).State = System.Data.Entity.EntityState.Detached;
|
|
db.Contacto.Attach(model);
|
|
db.Entry(model).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (DbEntityValidationException exs)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logger.Error(exs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ValorRetorno.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
logger.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
actual = null;
|
|
}
|
|
return ValorRetorno;
|
|
}
|
|
}
|
|
}
|