| 123456789101112131415161718192021222324252627 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Forum.Trash.Post.Restore;
- public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
- {
- public async Task Handle(Command request, CancellationToken ct)
- {
- if (request.IDs is null || request.IDs.Length == 0)
- {
- return;
- }
- var posts = await db.Post.Where(c => request.IDs.Contains(c.ID) && c.IsDeleted).ToListAsync(ct);
- foreach (var post in posts)
- {
- post.IsDeleted = false;
- post.DeletedAt = null;
- post.UpdatedAt = DateTime.UtcNow;
- }
- await db.SaveChangesAsync(ct);
- }
- }
|