using HelpDesk.Models.Entities; using Microsoft.EntityFrameworkCore; namespace HelpDesk.Data.Repositories; public class TicketCommentRepository : ITicketCommentRepository { private readonly HelpDeskDbContext _context; public TicketCommentRepository(HelpDeskDbContext context) { _context = context; } public async Task GetByIdAsync(Guid id) => await _context.TicketComments.FindAsync(id); public async Task> GetByTicketIdAsync(Guid ticketId) => await _context.TicketComments .Include(c => c.User) .Where(c => c.TicketId == ticketId) .OrderBy(c => c.CreatedAt) .ToListAsync(); public async Task CreateAsync(TicketComment comment) { _context.TicketComments.Add(comment); await _context.SaveChangesAsync(); return comment; } public async Task DeleteAsync(Guid id) { var comment = await _context.TicketComments.FindAsync(id); if (comment == null) return false; _context.TicketComments.Remove(comment); await _context.SaveChangesAsync(); return true; } } public class GroupRepository : IGroupRepository { private readonly HelpDeskDbContext _context; public GroupRepository(HelpDeskDbContext context) { _context = context; } public async Task GetByIdAsync(Guid id) => await _context.Groups.FindAsync(id); public async Task> GetAllAsync() => await _context.Groups.OrderBy(g => g.Name).ToListAsync(); public async Task CreateAsync(Group group) { _context.Groups.Add(group); await _context.SaveChangesAsync(); return group; } public async Task UpdateAsync(Group group) { var existing = await _context.Groups.FindAsync(group.Id); if (existing == null) return null; existing.Name = group.Name; existing.Description = group.Description; existing.IsActive = group.IsActive; await _context.SaveChangesAsync(); return existing; } public async Task DeleteAsync(Guid id) { var group = await _context.Groups.FindAsync(id); if (group == null) return false; _context.Groups.Remove(group); await _context.SaveChangesAsync(); return true; } } public class SLARepository : ISLARepository { private readonly HelpDeskDbContext _context; public SLARepository(HelpDeskDbContext context) { _context = context; } public async Task GetByIdAsync(Guid id) => await _context.SLAPolicies.FindAsync(id); public async Task> GetAllAsync() => await _context.SLAPolicies.OrderBy(s => s.Name).ToListAsync(); public async Task CreateAsync(SLAPolicy policy) { _context.SLAPolicies.Add(policy); await _context.SaveChangesAsync(); return policy; } public async Task UpdateAsync(SLAPolicy policy) { var existing = await _context.SLAPolicies.FindAsync(policy.Id); if (existing == null) return null; existing.Name = policy.Name; existing.Description = policy.Description; existing.ResponseTimeHours = policy.ResponseTimeHours; existing.ResolutionTimeHours = policy.ResolutionTimeHours; existing.IsActive = policy.IsActive; await _context.SaveChangesAsync(); return existing; } public async Task DeleteAsync(Guid id) { var policy = await _context.SLAPolicies.FindAsync(id); if (policy == null) return false; _context.SLAPolicies.Remove(policy); await _context.SaveChangesAsync(); return true; } }