Beispiel #1
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();
            }
        }
Beispiel #2
0
        public async Task ExecuteAsync(
            UserId userId,
            ChannelId channelId,
            ValidAcceptedChannelPrice acceptedPrice,
            DateTime now)
        {
            userId.AssertNotNull("userId");
            channelId.AssertNotNull("channelId");
            acceptedPrice.AssertNotNull("acceptedPrice");

            using (var transaction = TransactionScopeBuilder.CreateAsync())
            {
                using (var connection = this.connectionFactory.CreateConnection())
                {
                    var channelSubscription = new ChannelSubscription(
                        channelId.Value,
                        null,
                        userId.Value,
                        null,
                        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();
            }
        }