Add project files

This commit is contained in:
2025-10-04 13:27:29 +03:00
parent 75eba696c9
commit cc53824229
46 changed files with 3328 additions and 7 deletions

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using T120B165_ImgBoard.Data;
using File = T120B165_ImgBoard.Models.File;
namespace T120B165_ImgBoard.Services;
public interface IFileService
{
public Task<File?> GetFileById(long id);
Task<File> Update(File file);
Task Delete(File file);
}
public class FileService(ImgBoardContext context): IFileService
{
public async Task<File?> GetFileById(long id)
{
return await context.Files.Where(f => f.Id == id).FirstOrDefaultAsync();
}
public async Task<File> Update(File file)
{
context.Files.Update(file);
await context.SaveChangesAsync();
return file;
}
public async Task Delete(File file)
{
var actualFile = await GetFileById(file.Id);
context.Files.Remove(actualFile);
await context.SaveChangesAsync();
}
}