-
Notifications
You must be signed in to change notification settings - Fork 9
/
ProductsController.cs
45 lines (41 loc) · 1.5 KB
/
ProductsController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Cors;
using DevExtreme.AspNet.Mvc;
using DevExtreme.AspNet.Data;
using System.IO;
using DataSourceWebApi.Models;
using DataSourceWebApi.Services;
namespace DataSourceWebApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[EnableCors("AllowAll")]
public class ProductsController : ControllerBase
{
private readonly ExportHelper _eh;
private readonly NWINDContext _context;
public ProductsController(NWINDContext context, ExportHelper eh) {
_context = context;
_eh = eh;
}
// GET: api/Products
[HttpGet]
public object Products(DataSourceLoadOptions loadOptions) {
return DataSourceLoader.Load(_context.Products, loadOptions);
}
[HttpGet]
public async Task<ActionResult> ExportedDocument(DataSourceLoadOptions loadOptions, string format) {
loadOptions.Skip = 0;
loadOptions.Take = 0;
byte[] content = await _eh.ExportResult(DataSourceLoader.Load(_context.Products.ToList(), loadOptions), format);
string fileName = "DataGrid." + format;
string mimeType = "application/octet-stream";
return new FileStreamResult(new MemoryStream(content), mimeType) {
FileDownloadName = fileName
};
}
}
}