public IActionResult CrearEditarContacto(IList <CCPersonalizadosViewModel> cpViewModel, ContactoViewModel cViewModel, IList <TbFdCondicionesDePago> cPagoViewModel) { try { var existeContacto = contactoService.GetByCedulaContacto(cViewModel.Cedula); var contacto = new TbCrContacto(); if (cViewModel.IdContacto != 0) { if (existeContacto != null && existeContacto.IdContacto != cViewModel.IdContacto) { return(Json(new { success = false })); } contacto = contactoMap.UpdateContacto(cViewModel); contactoService.CreateOrUpdateCondicionPago(cPagoViewModel); var listaCCPCrear = new List <CCPersonalizadosViewModel>(); var listaCCPAct = new List <CCPersonalizadosViewModel>(); foreach (var item in cpViewModel) { if (item.Id != 0) { listaCCPAct.Add(item); } else { listaCCPCrear.Add(item); } } if (listaCCPCrear.Count() != 0) { ccMap.Create(listaCCPCrear, (int)cViewModel.IdContacto); } else { ccMap.Update(listaCCPAct, (int)cViewModel.IdContacto); } return(Json(new { success = true, accion = true, id = contacto.IdContacto, nombre = contacto.Cedula })); } else { if (existeContacto != null) { return(Json(new { success = false })); } contacto = contactoMap.CreateContacto(cViewModel); foreach (var item in cPagoViewModel) { item.IdContacto = contacto.IdContacto; } contactoService.CreateOrUpdateCondicionPago(cPagoViewModel); ccMap.Create(cpViewModel, (int)contacto.IdContacto); return(Json(new { success = true, accion = false, id = contacto.IdContacto })); } } catch (Exception ex) { AltivaLog.Log.Insertar(ex.ToString(), "Error"); throw; } }