Exemplo n.º 1
0
        public async Task <IActionResult> ProductStatsDownload(string format = "csv")
        {
            var stats = await _orderQueries.GetProductStatsAsync(null);

            var typedStats = stats
                             .Select(c => new { c.next, c.productId, c.year, c.month, c.units, c.avg, c.count, c.max, c.min, c.prev })
                             .ToList();

            switch (format.ToLower())
            {
            case "csv":
                var csvFile = File(Encoding.UTF8.GetBytes(typedStats.FormatAsCSV()), "text/csv");
                csvFile.FileDownloadName = "products.stats.csv";
                return(csvFile);

            case "json":
                return(Ok(typedStats));

            default:
                return(BadRequest());
            }
        }