public async Task <IActionResult> ProductStats(string format = "csv") { var productInfo = await catalogService.GetProductInfoAsync(); var productSales = await orderingService.GetProductSalesAsync(); var join = productInfo.Join(productSales, a => a.id, b => b.productId, (a, b) => new { b.next, b.productId, b.year, b.month, b.units, b.avg, b.count, b.max, b.min, b.prev, a.price, a.color, a.size, a.shape, a.agram, a.bgram, a.ygram, a.zgram }).ToList(); switch (format.ToLower()) { case "csv": var csvFile = File(Encoding.UTF8.GetBytes(join.FormatAsCSV()), "text/csv"); csvFile.FileDownloadName = "orderItems.stats.csv"; return(csvFile); case "json": return(Ok(join)); default: return(BadRequest()); } }