Skip to content

#improvement #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ namespace jQueryDatatableServerSideNetCore.Controllers
public class TestRegistersController : Controller
{
private readonly ApplicationDbContext _context;
private readonly IExportService _exportService;
private readonly IExportService<TestRegister> _exportService;

/// <summary>Initializes a new instance of the <see cref="TestRegistersController" /> class.</summary>
/// <param name="context">The context.</param>
/// <param name="exportService">The export service.</param>
public TestRegistersController(ApplicationDbContext context, IExportService exportService)
public TestRegistersController(ApplicationDbContext context, IExportService<TestRegister> exportService)
{
_context = context;
_exportService = exportService;
Expand Down
2 changes: 1 addition & 1 deletion src/jQueryDatatableServerSideNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
options.SerializerSettings.Converters.Add(new StringEnumConverter());
});

builder.Services.AddScoped<IExportService, ExportService>();
builder.Services.AddScoped(typeof(IExportService<>), typeof(ExportService<>));
builder.Services.AddScoped<IExcelService, ExcelService>();
builder.Services.AddScoped<ICsvService, CsvService>();
builder.Services.AddScoped<IHtmlService, HtmlService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace jQueryDatatableServerSideNetCore.Services.ExportService
{
public class ExportService : IExportService
public class ExportService<TModel> : IExportService<TModel> where TModel : class
{
private readonly IExcelService _excelService;
private readonly ICsvService _csvService;
Expand All @@ -28,32 +28,32 @@ public ExportService(IExcelService excelService, ICsvService csvService, IHtmlSe
_yamlService = yamlService;
}

public async Task<byte[]> ExportToExcel(List<TestRegister> registers)
public async Task<byte[]> ExportToExcel(List<TModel> registers)
{
return await _excelService.Write(registers);
}

public byte[] ExportToCsv(List<TestRegister> registers)
public byte[] ExportToCsv(List<TModel> registers)
{
return _csvService.Write(registers);
}

public byte[] ExportToHtml(List<TestRegister> registers)
public byte[] ExportToHtml(List<TModel> registers)
{
return _htmlService.Write(registers);
}

public byte[] ExportToJson(List<TestRegister> registers)
public byte[] ExportToJson(List<TModel> registers)
{
return _jsonService.Write(registers);
}

public byte[] ExportToXml(List<TestRegister> registers)
public byte[] ExportToXml(List<TModel> registers)
{
return _xmlService.Write(registers);
}

public byte[] ExportToYaml(List<TestRegister> registers)
public byte[] ExportToYaml(List<TModel> registers)
{
return _yamlService.Write(registers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

namespace jQueryDatatableServerSideNetCore.Services.ExportService
{
public interface IExportService
public interface IExportService<TModel> where TModel : class
{
Task<byte[]> ExportToExcel(List<TestRegister> registers);
Task<byte[]> ExportToExcel(List<TModel> registers);

byte[] ExportToCsv(List<TestRegister> registers);
byte[] ExportToCsv(List<TModel> registers);

byte[] ExportToHtml(List<TestRegister> registers);
byte[] ExportToHtml(List<TModel> registers);

byte[] ExportToJson(List<TestRegister> registers);
byte[] ExportToJson(List<TModel> registers);

byte[] ExportToXml(List<TestRegister> registers);
byte[] ExportToXml(List<TModel> registers);

byte[] ExportToYaml(List<TestRegister> registers);
byte[] ExportToYaml(List<TModel> registers);
}
}