Example #1
0
        // Listar Ultimos Adicionados
        public async Task <RendaDto[]> GetUltimosRendaAdd()
        {
            try
            {
                var todasRendas = await _repo.GetAllRenda();

                var lastRendasAdd = todasRendas.OrderByDescending(
                    x => x.Id
                    ).Take(3);

                var lastRendaDto = _map.Map <RendaDto[]>(lastRendasAdd);

                return(lastRendaDto.ToArray());
            }
            catch (System.Exception e)
            {
                throw new ArgumentException($"RENDA: Erro ao listar ultimos. CODE: {e.Message}");
            }
        }
Example #2
0
        // Valores Dividas por Usuario
        public async Task <DividaValoresDto> ValorTotal(int idUser)
        {
            try
            {
                var todasDividas = await _repo.GetAllDivida();

                var todasRendas = await _repo.GetAllRenda();

                // Rendas
                decimal totalRendas = todasRendas.Where(x => x.UserId == idUser).Sum(x => x.Valor);
                // Dividas
                decimal dividasPagas = todasDividas.Where(
                    x => x.UserId == idUser && x.Situacao == 1
                    ).Sum(
                    x => x.ValorTotal
                    );
                decimal todasDividasPendentes = todasDividas.Where(
                    x => x.UserId == idUser && x.Situacao == 0
                    ).Sum(
                    x => x.ValorTotal
                    );
                decimal todasDividasPorIdUser = todasDividas.Where(
                    x => x.UserId == idUser
                    ).Sum(x => x.ValorParcela);
                DividaValoresDto dividaValoresDto = new DividaValoresDto();

                dividaValoresDto.ValorTotalDividasPorId     = todasDividasPorIdUser;
                dividaValoresDto.ValorTotalDividasPagas     = dividasPagas;
                dividaValoresDto.ValorTotalDividasPendentes = todasDividasPendentes;
                dividaValoresDto.RendaBruta   = totalRendas;
                dividaValoresDto.RendaLiquida = totalRendas - todasDividasPendentes;


                return(dividaValoresDto);
            } catch (System.Exception e)
            {
                throw new ArgumentException($"DIVIDA: Erro ao listar valor total da divida por id. CODE: {e.Message}");
            }
        }