public Task <bool> IsWriteAllowedAsync(UserId requester, Shared.ChannelId channelId) { requester.AssertNotNull("requester"); channelId.AssertNotNull("channelId"); return(this.channelOwnership.IsOwnerAsync(requester, channelId)); }
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); } }
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 })); } }