45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
||
|
namespace ImageBoardServerApp.Data.Repository;
|
||
|
|
||
|
public static class ReportsRepository
|
||
|
{
|
||
|
public static async Task<List<ReportData>> getReportsAsync()
|
||
|
{
|
||
|
await using var db = new AppDBContext();
|
||
|
return await db.Reports.ToListAsync();
|
||
|
}
|
||
|
|
||
|
public static async Task<ReportData> getReportByIdAsync(int reportId)
|
||
|
{
|
||
|
await using var db = new AppDBContext();
|
||
|
return await db.Reports.FirstOrDefaultAsync(report => report.ReportID == reportId);
|
||
|
}
|
||
|
|
||
|
public static async Task<int> createReportAsync(ReportData reportData)
|
||
|
{
|
||
|
await using var db = new AppDBContext();
|
||
|
await db.Reports.AddAsync(reportData);
|
||
|
if (await db.SaveChangesAsync() >= 1)
|
||
|
{
|
||
|
return reportData.ReportID;
|
||
|
}
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
public static async Task<bool> updateReportAsync(ReportData reportData)
|
||
|
{
|
||
|
await using var db = new AppDBContext();
|
||
|
db.Reports.Update(reportData);
|
||
|
return await db.SaveChangesAsync() >= 1;
|
||
|
}
|
||
|
|
||
|
public static async Task<bool> deleteReportAsync(int reportId)
|
||
|
{
|
||
|
await using var db = new AppDBContext();
|
||
|
ReportData reportData = await getReportByIdAsync(reportId);
|
||
|
db.Remove(reportData);
|
||
|
return await db.SaveChangesAsync() >= 1;
|
||
|
}
|
||
|
}
|