Files
hcs/Hcs.WebApp/Services/FileToParseService.cs

44 lines
1.5 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<FileToParse> GetFileToParseByOperationIdAsync(HcsDbContext context, int operationId)
{
return await context.FilesToParse.SingleAsync(x => x.LastParseOperationId == operationId);
}
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();
}
}
}