@ AgaveJoe
The first intention that I have is to put some elements from the file table (Name, Type, Date...) in FileDescription class to render it and have acces to the file.
I don't use the procedure.
This elements must put in GetCustomers method.
1 - I need to recover the access path, I think to do that
FileDescription results = _context.Set<FileDescription>().FromSqlRaw("SELECT FileTableRootPath() as Name").FirstOrDefaultAsync();
2 - Put the element of file table in class FileDescription
string[] FileName = context.FileDescriptions.FromSqlRaw("SELECT*FROM dbo.wSerie").ToList();
The FileDescription has defined as below:
public class FileDescription
{
[NotMapped]
public string Name { get; set; } = string.Empty;
public string Description { get; set; }
public DateTime CreatedTimestamp { get; set; }
public DateTime UpdatedTimestamp { get; set; }
public string ContentType { get; set; }
}
I defined the ApplicationDbContext
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<FileDescription> FileDescriptions { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<FileDescription>().HasNoKey().ToTable("FileDescription", t => t.ExcludeFromMigrations());
base.OnModelCreating(modelBuilder);
}
}
Connextion
"ConnectionStrings": {
"DefaultConnection": "Data Source=servername;Initial Catalog=wSERIE;Trusted_Connection=True"
}
FileController
[Route("api/[controller]")]
[ApiController]
public class FileController : Controller
{
private readonly ApplicationDbContext context;
public FileController(ApplicationDbContext context)
{
this.context = context;
}
[HttpPost]
public IActionResult GetCustomers()
{
try
{
var draw = Request.Form["draw"].FirstOrDefault();
var start = Request.Form["start"].FirstOrDefault();
var length = Request.Form["length"].FirstOrDefault();
var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();
var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();
var searchValue = Request.Form["search[value]"].FirstOrDefault();
int pageSize = length != null ? Convert.ToInt32(length) : 0;
int skip = start != null ? Convert.ToInt32(start) : 0;
int recordsTotal = 0;
var customerData = (from tempcustomer in context.FileDescriptions select tempcustomer);
if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection)))
{
customerData = customerData.OrderBy(sortColumn + " " + sortColumnDirection);
}
if (!string.IsNullOrEmpty(searchValue))
{
customerData = customerData.Where(m => m.Name.Contains(searchValue));
// || m.Description.Contains(searchValue)
// || m.ContentType.Contains(searchValue));
}
recordsTotal = customerData.Count();
var data = customerData.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data };
return Ok(jsonData);
}
catch (Exception ex)
{
throw;
}
}
}
The customerDatatable
$(document).ready(function () {
$('#customerDatatable').dataTable({
"processing": true,
"serverSide": true,
"filter": true,
"ajax": {
"url": "/api/file",
"type": "POST",
"datatype": "json"
},
"columnDefs": [{
"targets": [0],
"visible": false,
"searchable": false
}],
"columns": [
// { "data": "id", "name": "Id", "autoWidth": true },
{ "data": "name", "name": "Name", "autoWidth": true },
{ "data": "description", "name": "Description", "autoWidth": true },
{ "data": "createdTimestamp", "name": "CreatedTimestamp", "autoWidth": true },
{ "data": "updatedTimestamp", "name": "UpdatedTimestamp", "autoWidth": true },
{ "data": "contentType", "name": "ContentType", "autoWidth": true },
]
});
});