コード例 #1
0
        public async Task <GetBlogSubscriberInformationDbStatementResult> ExecuteAsync(BlogId blogId)
        {
            blogId.AssertNotNull("blogId");

            using (var connection = this.connectionFactory.CreateConnection())
            {
                var result = await connection.QueryAsync <InternalResult>(
                    Sql,
                    new
                {
                    BlogId = blogId.Value,
                });

                return(new GetBlogSubscriberInformationDbStatementResult(
                           result.Select(v =>
                                         new GetBlogSubscriberInformationDbStatementResult.Subscriber(
                                             new Username(v.Username),
                                             new UserId(v.UserId),
                                             v.ProfileImageFileId == null ? null : new FileId(v.ProfileImageFileId.Value),
                                             new ChannelId(v.ChannelId),
                                             DateTime.SpecifyKind(v.SubscriptionStartDate, DateTimeKind.Utc),
                                             v.AcceptedPrice,
                                             v.Email == null ? null : new Email(v.Email),
                                             v.PaymentStatus == null ? PaymentStatus.None : v.PaymentStatus.Value,
                                             v.HasPaymentInformation)).ToList()));
            }
        }
コード例 #2
0
        public Task <bool> IsWriteAllowedAsync(UserId requester, BlogId blogId)
        {
            requester.AssertNotNull("requester");
            blogId.AssertNotNull("blogId");

            return(this.blogOwnership.IsOwnerAsync(requester, blogId));
        }
コード例 #3
0
        public async Task AssertWriteAllowedAsync(UserId requester, BlogId blogId)
        {
            requester.AssertNotNull("requester");
            blogId.AssertNotNull("blogId");

            var isUpdateAllowed = await this.IsWriteAllowedAsync(requester, blogId);

            if (!isUpdateAllowed)
            {
                throw new UnauthorizedException("Not allowed to update blog. {0} {1}", requester, blogId);
            }
        }
コード例 #4
0
        public async Task ExecuteAsync(UserId userId, BlogId blogId, IReadOnlyList <AcceptedChannelSubscription> channels, DateTime now)
        {
            userId.AssertNotNull("userId");
            blogId.AssertNotNull("blogId");

            if (channels == null || channels.Count == 0)
            {
                channels = new List <AcceptedChannelSubscription>();
            }

            using (var transaction = TransactionScopeBuilder.CreateAsync())
            {
                using (var connection = this.connectionFactory.CreateConnection())
                {
                    await connection.ExecuteAsync(
                        DeleteStatement,
                        new
                    {
                        BlogId         = blogId.Value,
                        SubscriberId   = userId.Value,
                        KeepChannelIds = channels.Select(v => v.ChannelId.Value).ToList()
                    });

                    foreach (var item in channels)
                    {
                        var channelSubscription = new ChannelSubscription(
                            item.ChannelId.Value,
                            null,
                            userId.Value,
                            null,
                            item.AcceptedPrice.Value,
                            now,
                            now);

                        const ChannelSubscription.Fields UpdateFields
                            = ChannelSubscription.Fields.AcceptedPrice
                              | ChannelSubscription.Fields.PriceLastAcceptedDate;

                        await connection.UpsertAsync(
                            channelSubscription,
                            UpdateFields);
                    }
                }

                await this.requestSnapshot.ExecuteAsync(userId, SnapshotType.SubscriberChannels);

                transaction.Complete();
            }
        }
コード例 #5
0
        public async Task <GetFreeAccessUsersResult> ExecuteAsync(BlogId blogId)
        {
            blogId.AssertNotNull("blogId");

            using (var connection = this.connectionFactory.CreateConnection())
            {
                var queryResult = (await connection.QueryAsync <QueryResult>(
                                       Query,
                                       new { BlogId = blogId.Value })).ToList();

                var result = new List <GetFreeAccessUsersResult.FreeAccessUser>();
                foreach (var groupedItem in queryResult.GroupBy(v => v.Email))
                {
                    var email     = groupedItem.Key;
                    var firstItem = groupedItem.First();

                    if (firstItem.Id.HasValue)
                    {
                        var channelIds
                            = firstItem.ChannelId == null
                            ? EmptyChannelIds
                            : groupedItem.Select(v => new ChannelId(v.ChannelId.Value)).ToList();

                        var output = new GetFreeAccessUsersResult.FreeAccessUser(
                            new Email(email),
                            new UserId(firstItem.Id.Value),
                            new Username(firstItem.UserName),
                            channelIds);

                        result.Add(output);
                    }
                    else
                    {
                        var output = new GetFreeAccessUsersResult.FreeAccessUser(
                            new Email(email),
                            null,
                            null,
                            EmptyChannelIds);

                        result.Add(output);
                    }
                }

                return(new GetFreeAccessUsersResult(result));
            }
        }
コード例 #6
0
        public async Task ExecuteAsync(UserId userId, BlogId blogId, IReadOnlyList <ValidEmail> emails)
        {
            userId.AssertNotNull("userId");
            blogId.AssertNotNull("blogId");

            if (emails == null)
            {
                emails = new List <ValidEmail>();
            }

            using (var transaction = TransactionScopeBuilder.CreateAsync())
            {
                using (var connection = this.connectionFactory.CreateConnection())
                {
                    if (emails.Count == 0)
                    {
                        await connection.ExecuteAsync(
                            DeleteQuery,
                            new { BlogId = blogId.Value });
                    }
                    else
                    {
                        await connection.ExecuteAsync(
                            DeleteQuery,
                            new { BlogId = blogId.Value });

                        await connection.ExecuteAsync(
                            AddQuery,
                            emails.Select(v => new { BlogId = blogId.Value, Email = v.Value }).ToList());
                    }
                }

                await this.requestSnapshot.ExecuteAsync(userId, SnapshotType.CreatorFreeAccessUsers);

                transaction.Complete();
            }
        }