| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using Microsoft.AspNetCore.Http;
-
- namespace Diligent.WebAPI.Business.Services
- {
- public class ImportService : IImportService
- {
- private readonly ILogger<ImportService> _logger;
- private readonly ISaveImportedDataService _service;
-
- public ImportService(ILogger<ImportService> logger, ISaveImportedDataService service)
- {
- _logger = logger;
- _service = service;
- }
- public async Task<List<ApplicantImportDto>> Import(IFormFile fileData)
- {
- try
- {
- using (var stream = new MemoryStream())
- {
- fileData.CopyTo(stream);
- var FileData = stream.ToArray();
- CopyFileToDirectory(FileData);
- }
- return await _service.Save();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- return new List<ApplicantImportDto>();
- }
- private async Task CopyFileToDirectory(byte[] FileData)
- {
- try
- {
- var content = new System.IO.MemoryStream(FileData);
- var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", "s.xlsx");
-
- await CopyStream(content, path);
- }
- catch (Exception)
- {
- throw;
- }
- }
- private async Task CopyStream(Stream stream, string downloadPath)
- {
- using (var fileStream = new FileStream(downloadPath, FileMode.Create, FileAccess.Write))
- {
- await stream.CopyToAsync(fileStream);
- }
- }
- }
- }
|