prog commit
This commit is contained in:
parent
4aec0f7cf0
commit
e65022fa3b
6 changed files with 124 additions and 2 deletions
|
@ -15,4 +15,7 @@ public class AccountData
|
|||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required]
|
||||
public int PermissionInteger { get; set; }
|
||||
}
|
53
ImageBoardServerApp/Data/Repository/AccountsRepository.cs
Normal file
53
ImageBoardServerApp/Data/Repository/AccountsRepository.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ImageBoardServerApp.Data.Repository;
|
||||
|
||||
public static class AccountsRepository
|
||||
{
|
||||
public static async Task<List<AccountData>> getAccountsAsync()
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
return await db.Accounts.ToListAsync();
|
||||
}
|
||||
|
||||
public static async Task<List<AccountData>> getAccountsByMailAsync(string email)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
return await db.Accounts
|
||||
.Where(acc => acc.Email.Equals(email))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public static async Task<AccountData> getAccountByIdAsync(int accountId)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
return await db.Accounts.FirstOrDefaultAsync(post => post.AccountID == accountId);
|
||||
}
|
||||
|
||||
public static async Task<int> 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<bool> updateAccountAsync(AccountData accountToUpdate)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
db.Accounts.Update(accountToUpdate);
|
||||
return await db.SaveChangesAsync() >= 1;
|
||||
}
|
||||
|
||||
public static async Task<bool> deleteAccountAsync(int postId)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
AccountData accountToDelete = await getAccountByIdAsync(postId);
|
||||
db.Remove(accountToDelete);
|
||||
return await db.SaveChangesAsync() >= 1;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue