public async Task <ISaida> CadastrarDetalhe(int idLancamento, LancamentoDetalheEntrada entrada) { // Verifica se as informações para cadastro foram informadas corretamente if (entrada.Invalido) { return(new Saida(false, entrada.Mensagens, null)); } var lancamento = await _lancamentoRepositorio.ObterPorId(idLancamento); // Verifica se o lançamento existe this.NotificarSeNulo(lancamento, LancamentoMensagem.Id_Lancamento_Nao_Existe); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } // Verifica se o valor do detalhe é maior que o valor do lançamento this.NotificarSeMaiorOuIgualA(entrada.Valor, lancamento.Valor, LancamentoDetalheMensagem.Valor_Detalhe_Maior_Ou_Igual_Valor_Lancamento); // Verifica se a categoria do detalhe é a mesma categoria informada para o lançamento. this.NotificarSeIguais(entrada.IdCategoria, lancamento.IdCategoria, LancamentoDetalheMensagem.Id_Categoria_Igual_Categoria_Lancamento); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } // Verifica se a soma dos valores dos detalhes do lançamento somado ao valor do detalhe é maior que o valor do lançamento this.NotificarSeMaiorQue(lancamento.Detalhes.Sum(x => x.Valor) + entrada.Valor, lancamento.Valor, LancamentoDetalheMensagem.Soma_Detalhes_Mais_Valor_Detalhe_Maior_Valor_Lancamento); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } var detalhe = new LancamentoDetalhe(idLancamento, entrada); await _detalheRepositorio.Inserir(detalhe); await _uow.Commit(); return(new Saida(true, new[] { LancamentoDetalheMensagem.Detalhe_Cadastrado_Com_Sucesso }, new LancamentoDetalheSaida(await _detalheRepositorio.ObterPorId(detalhe.Id)))); }
public LancamentoDetalheSaida(LancamentoDetalhe detalhe) { if (detalhe == null) { return; } this.Id = detalhe.Id; this.IdLancamento = detalhe.IdLancamento; this.Valor = detalhe.Valor; this.Observacao = detalhe.Observacao; this.Categoria = detalhe.Categoria != null ? new CategoriaSaida(detalhe.Categoria) : null; this.Lancamento = detalhe.Lancamento != null ? new LancamentoDetalheLancamentoSaida(detalhe.Lancamento) : null; }
public void Deletar(LancamentoDetalhe detalhe) { _efContext.LancamentosDetalhe.Remove(detalhe); }
public async Task Inserir(LancamentoDetalhe detalhe) { await _efContext.AddAsync(detalhe); }