コード例 #1
0
        public async Task <PaginatedList <TicketMessageDto> > Handle(GetTicketMessagesQuery request, CancellationToken cancellationToken)
        {
            await ValidateRequest(request);

            return(await _context.ConversationMessages
                   .Where(x => x.ConversationId == request.ConversationId)
                   .OrderBy(x => x.Created)
                   .ProjectTo <TicketMessageDto>(_mapper.ConfigurationProvider)
                   .PaginatedListAsync(request.PageNumber, request.PageSize));;
        }
コード例 #2
0
        private async Task ValidateRequest(GetTicketMessagesQuery request)

        {
            if (await _context.Conversations.AsNoTracking().AnyAsync(x => x.Id == request.ConversationId) == false)
            {
                throw new NotFoundException(nameof(Conversation), request.ConversationId);
            }

            if (await _context.ConversationUsers.AsNoTracking().AnyAsync(x => x.ConversationId == request.ConversationId && x.UserId == _currentUser.UserId && x.IsDisabled == false) == false)
            {
                throw new ForbiddenAccessException();
            }
        }