Ejemplo n.º 1
0
        public async Task <Statistic> GetStatistic(Guid userId)
        {
            DateTime  today     = DateTime.Now;
            Statistic statistic = new Statistic();

            for (int x = 0; x < 6; x++)
            {
                MonthSaldo saldo = await GetMonthSaldo(userId, today.Month, today.Year);

                statistic.Expenses.Add(Math.Abs(saldo.Expense));
                statistic.Income.Add(saldo.Income);
                statistic.Date.Add(today.ToString("yyyy-MM"));
                today = today.AddMonths(-1);
            }

            return(statistic);
        }
Ejemplo n.º 2
0
        private async Task <MonthSaldo> CountMonthSaldo(Guid userId, int month, int year)
        {
            List <Operation> operations = await GetUserOperations(userId, month, year);

            MonthSaldo saldo = new MonthSaldo(0, 0, 0);

            operations.ForEach(o =>
            {
                saldo.Saldo += o.Price;
                if (o.Price > 0)
                {
                    saldo.Income += o.Price;
                }
                else
                {
                    saldo.Expense += o.Price;
                }
            });

            return(saldo);
        }