using Microsoft.EntityFrameworkCore; using T120B165_ImgBoard.Data; using File = T120B165_ImgBoard.Models.File; namespace T120B165_ImgBoard.Services; public interface IFileService { public Task GetFileById(long id); Task Update(File file); Task Delete(File file); } public class FileService(ImgBoardContext context): IFileService { public async Task GetFileById(long id) { return await context.Files.Where(f => f.Id == id).FirstOrDefaultAsync(); } public async Task 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(); } }