| 1234567891011121314151617181920212223242526272829 |
- 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);
- }
- }
|