39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using Hcs.WebApp.Data.Hcs;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Hcs.WebApp.Services
|
|
{
|
|
public class FileToParseService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
|
{
|
|
public async Task<ICollection<FileToParse>> GetAllFilesToParseAsync()
|
|
{
|
|
using var context = GetNewContext();
|
|
return await context.FilesToParse.ToListAsync();
|
|
}
|
|
|
|
public async Task<FileToParse> AddFileToParseAsync(string path, string fileName, string uploaderId, DateTime uploadedAt)
|
|
{
|
|
using var context = GetNewContext();
|
|
var fileToParse = new FileToParse()
|
|
{
|
|
Path = path,
|
|
FileName = fileName,
|
|
UploaderId = uploaderId,
|
|
UploadedAt = uploadedAt
|
|
};
|
|
|
|
await context.FilesToParse.AddAsync(fileToParse);
|
|
await context.SaveChangesAsync();
|
|
return fileToParse;
|
|
}
|
|
|
|
public async Task SetOperationToFileToParseAsync(HcsDbContext context, int fileToParseId, Operation operation)
|
|
{
|
|
var fileToParse = await context.FilesToParse.FirstOrDefaultAsync(x => x.Id == fileToParseId);
|
|
fileToParse!.LastParseOperationId = operation.Id;
|
|
|
|
await context.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|