using API.Models; using Microsoft.EntityFrameworkCore; using Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Templates.BlazorIdentity.Pages; namespace API.Persistence.Repositories { public class UserRepository(AppDBContext context) : IUserRepository { private readonly AppDBContext _context = context; public async Task> QueryAllUsersAsync() { return await _context.Users.ToListAsync(); } public async Task QueryUserByIdAsync(string id) { try { return await _context.Users .FirstOrDefaultAsync(user => user.Id == id); } catch (Exception) { return new User(); } } public async Task CreateUserAsync(User user) { try { _context.Users.Add(user); await _context.SaveChangesAsync(); } catch (Exception) { return ""; } return user.Id; } public async Task UpdateUserAsync(User user) { try { _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception) { return false; } return true; } public async Task UpdateUserPasswordAsync(User user) { try { _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception) { return false; } return true; } public async Task DeleteUserAsync(string id) { var user = await _context.Users.FindAsync(id); if (user == null) { return false; } _context.Users.Remove(user); await _context.SaveChangesAsync(); return true; } public async Task QueryUserByEmailAsync(string email) { return await _context.Users.SingleOrDefaultAsync(u => u.Email == email); } } }