Exemplo n.º 1
0
        public Task <bool> IsWriteAllowedAsync(UserId requester, Shared.ChannelId channelId)
        {
            requester.AssertNotNull("requester");
            channelId.AssertNotNull("channelId");

            return(this.channelOwnership.IsOwnerAsync(requester, channelId));
        }
Exemplo n.º 2
0
        public async Task AssertWriteAllowedAsync(UserId requester, Shared.ChannelId channelId)
        {
            requester.AssertNotNull("requester");
            channelId.AssertNotNull("channelId");

            var isWriteAllowed = await this.IsWriteAllowedAsync(requester, channelId);

            if (!isWriteAllowed)
            {
                throw new UnauthorizedException("Not allowed to write to channel. {0} {1}", requester, channelId);
            }
        }
Exemplo n.º 3
0
        public async Task <bool> IsOwnerAsync(UserId userId, Shared.ChannelId channelId)
        {
            userId.AssertNotNull("userId");
            channelId.AssertNotNull("channelId");

            using (var connection = this.connectionFactory.CreateConnection())
            {
                return(await connection.ExecuteScalarAsync <bool>(
                           @"IF EXISTS(SELECT *
                                FROM        Channels channel
                                INNER JOIN  Blogs blog
                                    ON      channel.BlogId  = blog.Id
                                WHERE       channel.Id              = @ChannelId
                                AND         blog.CreatorId  = @CreatorId)
                        SELECT 1 AS FOUND
                    ELSE
                        SELECT 0 AS FOUND",
                           new
                {
                    ChannelId = channelId.Value,
                    CreatorId = userId.Value
                }));
            }
        }