using NetinaCMS.Repository.Repositories.Base.Contracts; namespace NetinaCMS.Repository.Handlers.Blogs; public class UpdateBlogCommandHandler : IRequestHandler { private readonly IRepositoryWrapper _repositoryWrapper; public UpdateBlogCommandHandler(IRepositoryWrapper repositoryWrapper) { _repositoryWrapper = repositoryWrapper; } public async Task Handle(UpdateBlogCommand request, CancellationToken cancellationToken) { var ent = await _repositoryWrapper.SetRepository() .TableNoTracking .FirstOrDefaultAsync(b => b.Id == request.Id, cancellationToken); if (ent == null) throw new AppException("Blog not found", ApiResultStatusCode.NotFound); var newEnt = Blog.Create(request.Title, request.Content, request.Tags, request.ReadingTime, request.Summery, request.IsSuggested, request.CategoryId); newEnt.CreatedAt = ent.CreatedAt; newEnt.CreatedBy = ent.CreatedBy; newEnt.Id = ent.Id; _repositoryWrapper.SetRepository() .Update(newEnt); await _repositoryWrapper.SaveChangesAsync(cancellationToken); return true; } }