31 lines
990 B
C#
31 lines
990 B
C#
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using ComplianceNFs.Core.Entities;
|
|
using ComplianceNFs.Core.Ports;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace ComplianceNFs.Infrastructure.Archiving
|
|
{
|
|
// Moves files to archive folders by status
|
|
public class FileArchiver(string basePath) : IFileArchiver
|
|
{
|
|
private readonly string _basePath = basePath;
|
|
|
|
public void ArchiveAsync(EnergyInvoice invoice)
|
|
{
|
|
var sourceFile = Path.Combine(_basePath, invoice.Filename);
|
|
// Create subfolder for invoice.Status
|
|
var statusFolder = Path.Combine(_basePath, invoice.Status.ToString());
|
|
if (!Directory.Exists(statusFolder))
|
|
{
|
|
Directory.CreateDirectory(statusFolder);
|
|
}
|
|
// Build file path
|
|
var filePath = Path.Combine(statusFolder, invoice.Filename);
|
|
// Write file (overwrite if exists)
|
|
File.Move(sourceFile, filePath);
|
|
}
|
|
}
|
|
}
|