using Microsoft.AspNetCore.Http; namespace Diligent.WebAPI.Business.Services { public class ImportService : IImportService { private readonly ILogger _logger; private readonly ISaveImportedDataService _service; public ImportService(ILogger logger, ISaveImportedDataService service) { _logger = logger; _service = service; } public async Task> 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(); } 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); } } } }