32 lines
1017 B
C#
32 lines
1017 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using SPMS.Domain.Entities;
|
|
using SPMS.Domain.Interfaces;
|
|
|
|
namespace SPMS.Infrastructure.Persistence.Repositories;
|
|
|
|
public class NoticeRepository : Repository<Notice>, INoticeRepository
|
|
{
|
|
public NoticeRepository(AppDbContext context) : base(context) { }
|
|
|
|
public async Task<(IReadOnlyList<Notice> Items, int TotalCount)> GetActivePagedAsync(long serviceId, int page, int size)
|
|
{
|
|
var query = _dbSet.Where(n => n.ServiceId == serviceId && n.IsActive);
|
|
|
|
var totalCount = await query.CountAsync();
|
|
|
|
var items = await query
|
|
.OrderByDescending(n => n.IsPinned)
|
|
.ThenByDescending(n => n.CreatedAt)
|
|
.Skip((page - 1) * size)
|
|
.Take(size)
|
|
.ToListAsync();
|
|
|
|
return (items, totalCount);
|
|
}
|
|
|
|
public async Task<Notice?> GetActiveByIdAsync(long id, long serviceId)
|
|
{
|
|
return await _dbSet.FirstOrDefaultAsync(n => n.Id == id && n.ServiceId == serviceId && n.IsActive);
|
|
}
|
|
}
|