using Microsoft.EntityFrameworkCore; namespace ImageBoardServerApp.Data.Repository; public static class UsersRepository { public static async Task> getUsersAsync() { await using var db = new AppDBContext(); return await db.Users .Include(user => user.SubmittedReports) .Include(user => user.RecivedReports) .Include(user => user.Comments) .Include(user => user.Posts) .ToListAsync(); } public static async Task getUserByIdAsync(int userId) { await using var db = new AppDBContext(); return await db.Users .Where(user => user.UserID == userId) .Include(user => user.SubmittedReports) .Include(user => user.Posts) .Include(user => user.Comments) .Include(user => user.RecivedReports) .FirstOrDefaultAsync(); } public static async Task getUserByIdLiteAsync(int userId) { await using var db = new AppDBContext(); return await db.Users .Where(x => x.UserID == userId) .FirstOrDefaultAsync(); } public static async Task getUserByEmailRawAsync(string email) { await using var db = new AppDBContext(); return await db.Users .Where(user => user.Email == email) .FirstOrDefaultAsync(); } public static async Task getUserByEmailAsync(string email) { await using var db = new AppDBContext(); return await db.Users .Where(user => user.Email == email) .Include(user => user.SubmittedReports) .Include(user => user.Posts) .Include(user => user.Comments) .Include(user => user.RecivedReports) .FirstOrDefaultAsync(); } public static async Task createUserAsync(UserData userToCreate) { await using var db = new AppDBContext(); await db.Users.AddAsync(userToCreate); if (await db.SaveChangesAsync() >= 1) { Console.WriteLine($"Created user with ID: {userToCreate.UserID}"); return userToCreate.UserID; } return -1; } public static async Task updateUserAsync(UserData userToUpdate) { await using var db = new AppDBContext(); db.Users.Update(userToUpdate); return await db.SaveChangesAsync() >= 1; } public static async Task deleteUserAsync(int userId) { await using var db = new AppDBContext(); UserData userToDelete = await getUserByIdAsync(userId); db.Remove(userToDelete); return await db.SaveChangesAsync() >= 1; } }