2025-12-29 14:18:09 +08:00
|
|
|
|
namespace Service;
|
|
|
|
|
|
|
|
|
|
|
|
public interface IMessageRecordService
|
|
|
|
|
|
{
|
|
|
|
|
|
Task<(IEnumerable<MessageRecord> List, long Total)> GetPagedListAsync(int pageIndex, int pageSize);
|
|
|
|
|
|
Task<MessageRecord?> GetByIdAsync(long id);
|
|
|
|
|
|
Task<bool> AddAsync(MessageRecord message);
|
|
|
|
|
|
Task<bool> AddAsync(string title, string content);
|
|
|
|
|
|
Task<bool> MarkAsReadAsync(long id);
|
|
|
|
|
|
Task<bool> MarkAllAsReadAsync();
|
|
|
|
|
|
Task<bool> DeleteAsync(long id);
|
|
|
|
|
|
Task<long> GetUnreadCountAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class MessageRecordService(IMessageRecordRepository messageRepo) : IMessageRecordService
|
|
|
|
|
|
{
|
|
|
|
|
|
public async Task<(IEnumerable<MessageRecord> List, long Total)> GetPagedListAsync(int pageIndex, int pageSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await messageRepo.GetPagedListAsync(pageIndex, pageSize);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<MessageRecord?> GetByIdAsync(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await messageRepo.GetByIdAsync(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> AddAsync(MessageRecord message)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await messageRepo.AddAsync(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> AddAsync(string title, string content)
|
|
|
|
|
|
{
|
|
|
|
|
|
var message = new MessageRecord
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = title,
|
|
|
|
|
|
Content = content,
|
|
|
|
|
|
IsRead = false
|
|
|
|
|
|
};
|
|
|
|
|
|
return await messageRepo.AddAsync(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> MarkAsReadAsync(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var message = await messageRepo.GetByIdAsync(id);
|
|
|
|
|
|
if (message == null) return false;
|
2026-01-01 12:32:08 +08:00
|
|
|
|
|
2025-12-29 14:18:09 +08:00
|
|
|
|
message.IsRead = true;
|
|
|
|
|
|
message.UpdateTime = DateTime.Now;
|
|
|
|
|
|
return await messageRepo.UpdateAsync(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> MarkAllAsReadAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
return await messageRepo.MarkAllAsReadAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> DeleteAsync(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await messageRepo.DeleteAsync(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<long> GetUnreadCountAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = await messageRepo.GetAllAsync();
|
|
|
|
|
|
return list.Count(x => !x.IsRead);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|