using Data.SeaHavenIndustries; using Microsoft.EntityFrameworkCore; using SeaHaven.DataServices.Interfaces; namespace SeaHaven.DataServices.Implementation { public class CommentDataService : ICommentDataService { private readonly ApplicationDbContext _context; public CommentDataService(ApplicationDbContext context) { _context = context; } public async Task GetByIdAsync(int id) { return await _context.Comments.FindAsync(id); } public async Task> GetAllAsync() { return await _context.Comments .Include(c => c.ApplicationUser) .ToListAsync(); } public async Task> GetByWorkOrderIdAsync(int workOrderId) { return await _context.Comments .Where(c => c.WorkerOrderId == workOrderId) .Include(c => c.ApplicationUser) .OrderBy(c => c.CreatedDate) .ToListAsync(); } public async Task> GetByDispatchIdAsync(int dispatchId) { return await _context.Comments .Where(c => c.DispatchId == dispatchId) .Include(c => c.ApplicationUser) .OrderBy(c => c.CreatedDate) .ToListAsync(); } public async Task AddAsync(Comments comment) { comment.CreatedDate = DateTime.UtcNow; await _context.Comments.AddAsync(comment); await _context.SaveChangesAsync(); return comment; } public async Task UpdateAsync(Comments comment) { _context.Comments.Update(comment); await _context.SaveChangesAsync(); } public async Task DeleteAsync(int id) { var entity = await GetByIdAsync(id); if (entity != null) { _context.Comments.Remove(entity); await _context.SaveChangesAsync(); } } public async Task ExistsAsync(int id) { return await _context.Comments.AnyAsync(c => c.Id == id); } } }