public async Task <Result <GuildChannelDto> > Handle(AddChannelCommand command, CancellationToken cancellationToken)
    {
        var channel = _mapper.Map <GuildChannel>(command);
        await _context.GuildChannels.AddAsync(channel, cancellationToken);

        await _context.SaveChangesAsync(cancellationToken);

        var dto = _mapper.Map <GuildChannelDto>(channel);

        return(await Result <GuildChannelDto> .SuccessAsync(dto));
    }
Ejemplo n.º 2
0
        public async Task <Result <GuildChannelDto> > Handle(GetChannelByDiscordIdQuery request, CancellationToken cancellationToken)
        {
            var channel = await _context.GuildChannels.FirstOrDefaultAsync(channel => channel.DiscordChannelId == request.DiscordChannelId, cancellationToken);

            if (channel == null)
            {
                //If the channel doesn't exist yet we register the user here.
                var addChannelCommand = new AddChannelCommand
                {
                    DiscordChannelId = request.DiscordChannelId,
                    GuildId          = request.GuildId
                };

                return(await _mediator.Send(addChannelCommand));
            }

            var mappedChannel = _mapper.Map <GuildChannelDto>(channel);

            return(await Result <GuildChannelDto> .SuccessAsync(mappedChannel));
        }