using Microsoft.EntityFrameworkCore; namespace ImageBoardServerApp.Data.Repository; public static class AccountsRepository { public static async Task> getAccountsAsync() { await using var db = new AppDBContext(); return await db.Accounts.ToListAsync(); } public static async Task> getAccountsByMailAsync(string email) { await using var db = new AppDBContext(); return await db.Accounts .Where(acc => acc.Email.Equals(email)) .ToListAsync(); } public static async Task getAccountByIdAsync(int accountId) { await using var db = new AppDBContext(); return await db.Accounts.FirstOrDefaultAsync(post => post.AccountID == accountId); } public static async Task createAccountAsync(AccountData accountToCreate) { await using var db = new AppDBContext(); await db.Accounts.AddAsync(accountToCreate); if (await db.SaveChangesAsync() >= 1) { Console.WriteLine($"Created post with ID: {accountToCreate.AccountID}"); return accountToCreate.AccountID; } return -1; } public static async Task updateAccountAsync(AccountData accountToUpdate) { await using var db = new AppDBContext(); db.Accounts.Update(accountToUpdate); return await db.SaveChangesAsync() >= 1; } public static async Task deleteAccountAsync(int postId) { await using var db = new AppDBContext(); AccountData accountToDelete = await getAccountByIdAsync(postId); db.Remove(accountToDelete); return await db.SaveChangesAsync() >= 1; } }