feat: added Reports to DB
This commit is contained in:
parent
e21ac0d3d7
commit
963711adfb
5 changed files with 67 additions and 0 deletions
45
ImageBoardServerApp/Data/Repository/ReportsRepository.cs
Normal file
45
ImageBoardServerApp/Data/Repository/ReportsRepository.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue