private SalesReportIndexViewModel BuildIndexModel()
        {
            _dax.OpenConnection();

            string daxQuery = @"
                EVALUATE
                VALUES(Calendario[Año])
                ORDER BY Calendario[Año] DESC";

            var reader = _dax.GetDaxResult(daxQuery);

            List <SelectListItem> years = new();

            while (reader.Read())
            {
                string year = reader[0].ToString();
                years.Add(new SelectListItem(year, year));
            }
            reader.Close();

            _dax.CloseConnection();
            return(new SalesReportIndexViewModel {
                Years = years
            });
        }
Beispiel #2
0
        private HomeIndexViewModel BuildIndexModel()
        {
            _dax.OpenConnection();

            var model = new HomeIndexViewModel();

            string daxQuery = @"
                DEFINE
                    VAR maxYear = MAX ( Calendario[Año] )
                EVALUATE
                    CALCULATETABLE (
                        ROW (
                            ""Unidades Vendidas"", [Unidades Vendidas],
                            ""Importe"", [Importe],
                            ""% Beneficiario"", [% Beneficio]
                        ),
                        Calendario[Año] = maxYear
                    )";

            using (var reader = _dax.GetDaxResult(daxQuery))
            {
                if (reader.Read())
                {
                    model.UnidadesVendidas = reader.GetInt64(0);
                    model.Importe          = reader.GetDecimal(1);
                    model.Beneficio        = reader.GetDecimal(2);
                }
                reader.Close();
            }

            _dax.CloseConnection();

            return(model);
        }