52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using FileService.Domain.Entities;
|
|
using FileService.Domain.IReposities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FileService.Infrastructure.Reposites
|
|
{
|
|
public class UploadFileReposity : IUploadFileReposity
|
|
{
|
|
private readonly FileDbContext db;
|
|
|
|
public UploadFileReposity(FileDbContext db)
|
|
{
|
|
this.db = db;
|
|
}
|
|
|
|
public void Create(UploadFile file)
|
|
{
|
|
db.Files.Add(file);
|
|
}
|
|
|
|
public async Task<UploadFile?> FindByCheckSumAsync(Guid uploaderId, string value)
|
|
{
|
|
return await db.Files.FirstOrDefaultAsync(
|
|
x => x.OwnerId == uploaderId &&
|
|
x.CheckSum.Value == value
|
|
);
|
|
}
|
|
|
|
public async Task<UploadFile?> FindByIdAsync(Guid id)
|
|
{
|
|
return await db.Files.FirstOrDefaultAsync(x => x.Id == id);
|
|
}
|
|
public async Task<UploadFile?> FindByCheckSumGlobalAsync(string algorithm, string value)
|
|
{
|
|
return await db.Files.FirstOrDefaultAsync(
|
|
x => x.CheckSum.Algorithm == algorithm &&
|
|
x.CheckSum.Value == value
|
|
);
|
|
}
|
|
|
|
public Task<UploadFile?> FindBySourceTaskIdAsync(Guid taskId)
|
|
{
|
|
return db.Files.FirstOrDefaultAsync(x => x.SourceTaskId == taskId);
|
|
}
|
|
}
|
|
}
|