Ejemplo n.º 1
0
        public JsonResult BarChartDataForTransactions()
        {
            var transactionsBarChart = new BarChartTransactions();

            // Get only My Household transactions
            var      householdTransactions = MainDashboardViewModel.Transactions.ToList();
            DateTime monthToReport         = DateTime.Now.AddMonths(-12);
            DateTime nextMonth             = DateTime.Now.AddMonths(1);
            DateTime dateTimeReportCutoff  = new DateTime(nextMonth.Year, nextMonth.Month, 1);
            var      oldestTransaction     = householdTransactions.OrderBy(t => t.TransactionDateTime).FirstOrDefault();

            if (oldestTransaction != null)
            {
                if (monthToReport < oldestTransaction.TransactionDateTime)
                {
                    monthToReport = oldestTransaction.TransactionDateTime;
                }
                // Collect list of Months to report based on earliestDateToReport into labels
                var months = new List <string>();
                var totals = new List <decimal>();
                do
                {
                    months.Add(monthToReport.ToString("MMMM"));

                    // For each month, sum the total transactions amount and collect into values
                    decimal sum = 0m;
                    foreach (var transaction in householdTransactions.Where(t => t.TransactionDateTime.Month == monthToReport.Month))
                    {
                        sum += transaction.Amount;
                    }
                    totals.Add(sum);

                    monthToReport = monthToReport.AddMonths(1);
                } while (monthToReport < dateTimeReportCutoff);

                transactionsBarChart.labels = months.ToArray();
                transactionsBarChart.values = totals.ToArray();
            }

            return(Json(transactionsBarChart));
        }
Ejemplo n.º 2
0
        public JsonResult BarChartDataTransactions()
        {
            var transactionsBarChart = new BarChartTransactions();

            return(Json(transactionsBarChart));
        }