Skip to content

Commit

Permalink
Merge pull request #12 from sametcekin/net-60
Browse files Browse the repository at this point in the history
#improvement
  • Loading branch information
DavidSuescunPelegay authored Sep 4, 2023
2 parents af8f4dc + 2ed55d7 commit 98ebccc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
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);
}
}

0 comments on commit 98ebccc

Please sign in to comment.