public Retorno Excluir(ContaPagar Entity) { try { var retorno = new Retorno(true); using (var transaction = new TransactionScope()) { retorno = new BusinessParcela().Excluir(Entity.Codigo); if (retorno.IsValido) { retorno = new DataContaPagar().Excluir(Entity); if (retorno.IsValido) { transaction.Complete(); } } return(retorno); } } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
public Retorno Salvar(ContaPagar Entity) { try { Retorno retorno = PreenchimentoObrigatorio(Entity); if (retorno.IsValido) { using (var transaction = new TransactionScope()) { if (Entity.Codigo == 0) { retorno = new DataContaPagar().Incluir(Entity); if (retorno.IsValido) { retorno = new BusinessParcela().Salvar(Entity); } } else { retorno = new DataContaPagar().Alterar(Entity); } if (retorno.IsValido) { transaction.Complete(); } } } return(retorno); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
public Retorno Listar(DateTime dataInicio, DateTime dataFim) { try { var retorno = new DataContaPagar().Listar(dataInicio, dataFim); var contasPagarDetalhada = new List <ContaPagar>(); if (retorno.IsValido) { var contasPagar = retorno.Entity as List <ContaPagar>; foreach (var contaPagar in contasPagar) { switch ((EnumTipoContaPagar)contaPagar.TipoContaPagar.Codigo) { case EnumTipoContaPagar.PARCELADA: retorno = new BusinessParcela().Consultar(contaPagar.Codigo, dataInicio, dataFim); if (retorno.IsValido) { contaPagar.Parcelas = retorno.Entity as List <Parcela>; foreach (var parcela in contaPagar.Parcelas) { retorno = new BusinessPagamento().Consultar(new Pagamento { ContaPagar = contaPagar, DataVencimento = parcela.DataVencimento }); if (retorno.IsValido) { var pagamento = retorno.Entity as Pagamento; contasPagarDetalhada.Add(CriarContaParcelada(contaPagar, parcela, pagamento.Codigo > 0)); } else { return(retorno); } } } break; case EnumTipoContaPagar.FIXA: var dataReferencia = dataInicio; var meses = 0; while (dataReferencia < dataFim) { retorno = new BusinessPagamento().Consultar(new Pagamento { ContaPagar = contaPagar, DataVencimento = contaPagar.DataVencimento.Value.AddMonths(meses) }); if (retorno.IsValido) { var pagamento = retorno.Entity as Pagamento; contasPagarDetalhada.Add(CriarContaFixa(contaPagar, meses, pagamento.Codigo > 0)); dataReferencia = dataReferencia.AddMonths(1); meses++; } else { return(retorno); } } break; case EnumTipoContaPagar.A_VISTA: retorno = new BusinessPagamento().Consultar(new Pagamento { ContaPagar = contaPagar, DataVencimento = contaPagar.DataVencimento.Value }); if (retorno.IsValido) { var pagamento = retorno.Entity as Pagamento; contaPagar.TipoStatusContaPagar.Codigo = pagamento.Codigo > 0 ? (int)EnumTipoStatusContaPagar.PAGO : contaPagar.DataVencimento < DateTime.Now ? (int)EnumTipoStatusContaPagar.ATRASADO : (int)EnumTipoStatusContaPagar.EM_ABERTO; contasPagarDetalhada.Add(contaPagar); } else { return(retorno); } break; default: break; } } if (retorno.IsValido) { retorno.Entity = contasPagarDetalhada.OrderBy(c => c.DataVencimento).ToList(); } } return(retorno); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }