private void AppendUserValuesToColumns(List <YearlySalesReportFlatDto> data)
        {
            for (int i = 0; i < dgvUserSalesList.Columns.Count; i++)
            {
                DataGridViewColumn column = dgvUserSalesList.Columns[i];
                int monthNumber           = GetColumnMonthNumber(column);

                //check if it's a month column
                if (monthNumber > 0)
                {
                    for (int j = 0; j < dgvUserSalesList.Rows.Count; j++)
                    {
                        var row = dgvUserSalesList.Rows[j];

                        DataGridViewTextBoxCell cell = row.Cells[i] as DataGridViewTextBoxCell;

                        MonthlySaleTotalDto userMonthlyTotal = data[j].MonthlyTotals.FirstOrDefault(x => x.MonthNumber == monthNumber);

                        if (userMonthlyTotal != null)
                        {
                            cell.Value = userMonthlyTotal.Total;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private List <MonthlySaleTotalDto> CalculateUserMonthlySales(int id, IEnumerable <Reservation> usersWithReservations)
        {
            List <MonthlySaleTotalDto> monthlySales = new List <MonthlySaleTotalDto>();

            for (int i = 0; i < 12; i++)
            {
                decimal monthlyTotal = usersWithReservations.Where(x => x.Invoice != null &&
                                                                   x.UserId == id &&
                                                                   x.CreatedAt.Month == i + 1)
                                       .Sum(x => x.Invoice.Price);
                MonthlySaleTotalDto monthlySale = new MonthlySaleTotalDto
                {
                    MonthNumber = i + 1,
                    Total       = monthlyTotal
                };

                monthlySales.Add(monthlySale);
            }

            return(monthlySales);
        }