133 lines
3.8 KiB
C#
133 lines
3.8 KiB
C#
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<TicketComment?> GetByIdAsync(Guid id)
|
|
=> await _context.TicketComments.FindAsync(id);
|
|
|
|
public async Task<IEnumerable<TicketComment>> GetByTicketIdAsync(Guid ticketId)
|
|
=> await _context.TicketComments
|
|
.Include(c => c.User)
|
|
.Where(c => c.TicketId == ticketId)
|
|
.OrderBy(c => c.CreatedAt)
|
|
.ToListAsync();
|
|
|
|
public async Task<TicketComment> CreateAsync(TicketComment comment)
|
|
{
|
|
_context.TicketComments.Add(comment);
|
|
await _context.SaveChangesAsync();
|
|
return comment;
|
|
}
|
|
|
|
public async Task<bool> 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<Group?> GetByIdAsync(Guid id)
|
|
=> await _context.Groups.FindAsync(id);
|
|
|
|
public async Task<IEnumerable<Group>> GetAllAsync()
|
|
=> await _context.Groups.OrderBy(g => g.Name).ToListAsync();
|
|
|
|
public async Task<Group> CreateAsync(Group group)
|
|
{
|
|
_context.Groups.Add(group);
|
|
await _context.SaveChangesAsync();
|
|
return group;
|
|
}
|
|
|
|
public async Task<Group?> 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<bool> 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<SLAPolicy?> GetByIdAsync(Guid id)
|
|
=> await _context.SLAPolicies.FindAsync(id);
|
|
|
|
public async Task<IEnumerable<SLAPolicy>> GetAllAsync()
|
|
=> await _context.SLAPolicies.OrderBy(s => s.Name).ToListAsync();
|
|
|
|
public async Task<SLAPolicy> CreateAsync(SLAPolicy policy)
|
|
{
|
|
_context.SLAPolicies.Add(policy);
|
|
await _context.SaveChangesAsync();
|
|
return policy;
|
|
}
|
|
|
|
public async Task<SLAPolicy?> 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<bool> DeleteAsync(Guid id)
|
|
{
|
|
var policy = await _context.SLAPolicies.FindAsync(id);
|
|
if (policy == null) return false;
|
|
_context.SLAPolicies.Remove(policy);
|
|
await _context.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
}
|