Initial commit: HelpDesk ICHN - .NET 10 backend + Next.js 16 frontend
This commit is contained in:
commit
359f0caf85
90 files changed
+13395
No files matched your search
@@ -0,0 +1,55 @@
|
||||
using HelpDesk.Models.Entities;
|
||||
using HelpDesk.Models.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HelpDesk.Data.Repositories;
|
||||
|
||||
public class UserRepository : IUserRepository
|
||||
{
|
||||
private readonly HelpDeskDbContext _context;
|
||||
|
||||
public UserRepository(HelpDeskDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<User?> GetByIdAsync(Guid id)
|
||||
=> await _context.Users.FirstOrDefaultAsync(u => u.Id == id);
|
||||
|
||||
public async Task<User?> GetByEmailAsync(string email)
|
||||
=> await _context.Users.FirstOrDefaultAsync(u => u.Email == email);
|
||||
|
||||
public async Task<IEnumerable<User>> GetAllAsync()
|
||||
=> await _context.Users.OrderBy(u => u.LastName).ToListAsync();
|
||||
|
||||
public async Task<IEnumerable<User>> GetByRoleAsync(UserRole role)
|
||||
=> await _context.Users.Where(u => u.Role == role && u.IsActive).OrderBy(u => u.LastName).ToListAsync();
|
||||
|
||||
public async Task<User> CreateAsync(User user)
|
||||
{
|
||||
_context.Users.Add(user);
|
||||
await _context.SaveChangesAsync();
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<User?> UpdateAsync(User user)
|
||||
{
|
||||
var existing = await _context.Users.FindAsync(user.Id);
|
||||
if (existing == null) return null;
|
||||
|
||||
existing.FirstName = user.FirstName;
|
||||
existing.LastName = user.LastName;
|
||||
existing.Email = user.Email;
|
||||
existing.PhoneNumber = user.PhoneNumber;
|
||||
existing.AvatarUrl = user.AvatarUrl;
|
||||
existing.Role = user.Role;
|
||||
existing.IsActive = user.IsActive;
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return existing;
|
||||
}
|
||||
|
||||
public async Task<bool> ExistsAsync(string email)
|
||||
=> await _context.Users.AnyAsync(u => u.Email == email);
|
||||
}
|
||||
Reference in new issue
Block a user