mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 11:53:12 +00:00
105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
|
|
using Data.SeaHavenIndustries;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using SeaHaven.DataServices.Interfaces;
|
||
|
|
|
||
|
|
namespace SeaHaven.DataServices.Implementation
|
||
|
|
{
|
||
|
|
public class FollowUpDataService : IFollowUpDataService
|
||
|
|
{
|
||
|
|
private readonly ApplicationDbContext _context;
|
||
|
|
|
||
|
|
public FollowUpDataService(ApplicationDbContext context)
|
||
|
|
{
|
||
|
|
_context = context;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<FollowUps?> GetByIdAsync(int id)
|
||
|
|
{
|
||
|
|
return await _context.FollowUps.FindAsync(id);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<FollowUps?> GetByIdWithDetailsAsync(int id)
|
||
|
|
{
|
||
|
|
return await _context.FollowUps
|
||
|
|
.FirstOrDefaultAsync(f => f.Id == id);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<IEnumerable<FollowUps>> GetAllAsync()
|
||
|
|
{
|
||
|
|
return await _context.FollowUps.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<IEnumerable<FollowUps>> GetByWorkOrderIdAsync(int workOrderId)
|
||
|
|
{
|
||
|
|
return await _context.FollowUps
|
||
|
|
.Where(f => f.WorkOrderId == workOrderId)
|
||
|
|
.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<IEnumerable<FollowUps>> GetByUserIdAsync(string userId)
|
||
|
|
{
|
||
|
|
return await _context.FollowUps
|
||
|
|
.Where(f => f.createdby == userId)
|
||
|
|
.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<(IEnumerable<FollowUps> Items, int TotalCount)> GetPagedAsync(
|
||
|
|
int page,
|
||
|
|
int pageSize,
|
||
|
|
string? search = null,
|
||
|
|
string? status = null)
|
||
|
|
{
|
||
|
|
var query = _context.FollowUps.AsQueryable();
|
||
|
|
|
||
|
|
if (!string.IsNullOrWhiteSpace(status))
|
||
|
|
{
|
||
|
|
query = query.Where(f => f.Status == status);
|
||
|
|
}
|
||
|
|
|
||
|
|
var totalCount = await query.CountAsync();
|
||
|
|
var items = await query
|
||
|
|
.OrderByDescending(f => f.CreatedDate)
|
||
|
|
.Skip((page - 1) * pageSize)
|
||
|
|
.Take(pageSize)
|
||
|
|
.ToListAsync();
|
||
|
|
|
||
|
|
return (items, totalCount);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<FollowUps> AddAsync(FollowUps followUp)
|
||
|
|
{
|
||
|
|
followUp.CreatedDate = DateTime.Now;
|
||
|
|
await _context.FollowUps.AddAsync(followUp);
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
return followUp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task UpdateAsync(FollowUps followUp)
|
||
|
|
{
|
||
|
|
followUp.LastModificationTime = DateTime.Now;
|
||
|
|
_context.FollowUps.Update(followUp);
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task DeleteAsync(int id)
|
||
|
|
{
|
||
|
|
var entity = await GetByIdAsync(id);
|
||
|
|
if (entity != null)
|
||
|
|
{
|
||
|
|
_context.FollowUps.Remove(entity);
|
||
|
|
await _context.SaveChangesAsync();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<bool> ExistsAsync(int id)
|
||
|
|
{
|
||
|
|
return await _context.FollowUps.AnyAsync(f => f.Id == id);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<int> CountAsync()
|
||
|
|
{
|
||
|
|
return await _context.FollowUps.CountAsync();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|