public ActionResult registrarPagamento(BaixaTituloDespesaPagamentoForm ViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("modal-registrar-pagamento", ViewModel));
            }

            ViewModel.listaTituloDespesaPagamento.ForEach(Item => {
                Item.dtPagamento        = ViewModel.TituloDespesaPagamento.dtPagamento;
                Item.idMeioPagamento    = ViewModel.TituloDespesaPagamento.idMeioPagamento;
                Item.valorPago          = ViewModel.TituloDespesaPagamento.valorOriginal;
                Item.valorOutrasTarifas = ViewModel.TituloDespesaPagamento.valorOutrasTarifas;
                Item.nroBanco           = ViewModel.TituloDespesaPagamento.nroBanco;
                Item.nroDocumento       = ViewModel.TituloDespesaPagamento.nroDocumento;
                Item.nroNotaFiscal      = ViewModel.TituloDespesaPagamento.nroNotaFiscal;
                Item.nroContrato        = ViewModel.TituloDespesaPagamento.nroContrato;
                Item.nroAgencia         = ViewModel.TituloDespesaPagamento.nroAgencia;
                Item.nroDigitoAgencia   = ViewModel.TituloDespesaPagamento.nroDigitoAgencia;
                Item.nroConta           = ViewModel.TituloDespesaPagamento.nroConta;
                Item.nroDigitoConta     = ViewModel.TituloDespesaPagamento.nroDigitoConta;
                Item.codigoAutorizacao  = ViewModel.TituloDespesaPagamento.codigoAutorizacao;
                Item.valorJuros         = ViewModel.TituloDespesaPagamento.valorJuros;
                Item.valorMulta         = ViewModel.TituloDespesaPagamento.valorMulta;
            });

            var ORetorno = UtilRetorno.newInstance(false);

            foreach (var OTituloDespesaPagamento in ViewModel.listaTituloDespesaPagamento)
            {
                var Retorno = this.OTituloDespesaPagamentoBL.registrarPagamento(OTituloDespesaPagamento);

                if (Retorno.flagError)
                {
                    ORetorno.flagError = true;
                }

                ORetorno.listaErros.Add($"Pagamento #{OTituloDespesaPagamento.id} - " + Retorno.listaErros.FirstOrDefault());
            }

            if (ORetorno.flagError)
            {
                this.Flash(UtilMessage.TYPE_MESSAGE_INFO, string.Join("<br/>", ORetorno.listaErros));
            }

            this.Flash(UtilMessage.TYPE_MESSAGE_SUCCESS, string.Join("<br/>", ORetorno.listaErros));

            return(PartialView("modal-registrar-pagamento", ViewModel));
        }
        public ActionResult modelRegistrarPagamento()
        {
            var ViewModel = new BaixaTituloDespesaPagamentoForm();

            List <int> ids = UtilRequest.getListInt("id");

            ViewModel.TituloDespesaPagamento = new TituloDespesaPagamento();
            ViewModel.TituloDespesaPagamento.TituloDespesa = new TituloDespesa();

            ViewModel.listaTituloDespesaPagamento = this.OTituloDespesaPagamentoBL.listar(0)
                                                    .Where(x => ids.Contains(x.id) && x.dtPagamento == null && x.TituloDespesa.dtQuitacao == null && x.TituloDespesa.dtExclusao == null).ToList();

            if (!ViewModel.listaTituloDespesaPagamento.Any())
            {
                this.Flash(UtilMessage.TYPE_MESSAGE_INFO, "Nenhum registro localizado");
                return(PartialView(ViewModel));
            }

            ViewModel.TituloDespesaPagamento.TituloDespesa = ViewModel.listaTituloDespesaPagamento.DistinctBy(x => x.idTituloDespesa).Count() == 1
                ? ViewModel.listaTituloDespesaPagamento.FirstOrDefault()?.TituloDespesa : new TituloDespesa();

            return(PartialView(ViewModel));
        }