namespace Brizco.Repository.Handlers.Sections; public class CreateSectionCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler { public async Task Handle(CreateSectionCommand request, CancellationToken cancellationToken) { if (currentUserService.ComplexId == null) throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound); if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId)) throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound); try { await repositoryWrapper.BeginTransaction(cancellationToken); var entity = Section .Create(request.Title, request.Description, complexId); repositoryWrapper.SetRepository
().Add(entity); await repositoryWrapper.SaveChangesAsync(cancellationToken); await repositoryWrapper.CommitAsync(cancellationToken); return entity.AdaptToSDto(); } catch (Exception) { await repositoryWrapper.RollBackAsync(cancellationToken); throw; } } }