mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 20:03:11 +00:00
76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
|
|
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<Comments?> GetByIdAsync(int id)
|
||
|
|
{
|
||
|
|
return await _context.Comments.FindAsync(id);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<IEnumerable<Comments>> GetAllAsync()
|
||
|
|
{
|
||
|
|
return await _context.Comments
|
||
|
|
.Include(c => c.ApplicationUser)
|
||
|
|
.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<IEnumerable<Comments>> GetByWorkOrderIdAsync(int workOrderId)
|
||
|
|
{
|
||
|
|
return await _context.Comments
|
||
|
|
.Where(c => c.WorkerOrderId == workOrderId)
|
||
|
|
.Include(c => c.ApplicationUser)
|
||
|
|
.OrderBy(c => c.CreatedDate)
|
||
|
|
.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<IEnumerable<Comments>> GetByDispatchIdAsync(int dispatchId)
|
||
|
|
{
|
||
|
|
return await _context.Comments
|
||
|
|
.Where(c => c.DispatchId == dispatchId)
|
||
|
|
.Include(c => c.ApplicationUser)
|
||
|
|
.OrderBy(c => c.CreatedDate)
|
||
|
|
.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<Comments> 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<bool> ExistsAsync(int id)
|
||
|
|
{
|
||
|
|
return await _context.Comments.AnyAsync(c => c.Id == id);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|