private static void OrderResults(GetUserSubscriptionsResult result) { ((List <BlogSubscriptionStatus>)result.Blogs).Sort((a, b) => a.BlogId.Value.CompareTo(b.BlogId.Value)); foreach (var blog in result.Blogs) { ((List <ChannelSubscriptionStatus>)blog.Channels).Sort((a, b) => a.ChannelId.Value.CompareTo(b.ChannelId.Value)); } }
public async Task <UserState> HandleAsync(GetUserStateQuery query) { query.AssertNotNull("query"); GetUserSubscriptionsResult userSubscriptions = null; GetAccountSettingsResult accountSettings = null; BlogWithFileInformation blog = null; if (query.RequestedUserId != null) { if (query.Impersonate) { var impersonatingRequester = await this.impersonateIfRequired.ExecuteAsync(query.Requester, query.RequestedUserId); if (impersonatingRequester != null) { query = new GetUserStateQuery(impersonatingRequester, query.RequestedUserId, false, query.Now); } } await this.requesterSecurity.AuthenticateAsAsync(query.Requester, query.RequestedUserId); var isCreator = await this.requesterSecurity.IsInRoleAsync(query.Requester, FifthweekRole.Creator); var blogSubscriptionsTask = this.getBlogSubscriptions.HandleAsync(new GetUserSubscriptionsQuery(query.Requester, query.RequestedUserId)); var accountSettingsTask = this.getAccountSettings.HandleAsync(new GetAccountSettingsQuery( query.Requester, query.RequestedUserId, query.Now)); if (isCreator) { var blogChannelsAndCollections = await this.getBlogChannelsAndQueues.HandleAsync(new GetBlogChannelsAndQueuesQuery(query.RequestedUserId)); if (blogChannelsAndCollections != null) { blog = blogChannelsAndCollections.Blog; } } accountSettings = await accountSettingsTask; userSubscriptions = await blogSubscriptionsTask; } List <ChannelId> creatorChannelIds = null; if (blog != null) { creatorChannelIds = blog.Channels.Select(v => v.ChannelId).Distinct().ToList(); } List <ChannelId> subscribedChannelIds = null; List <ChannelId> freeAccessChannelIds = null; if (userSubscriptions != null) { bool hasFunds = accountSettings != null && (accountSettings.AccountBalance > 0 || accountSettings.IsRetryingPayment); if (hasFunds) { subscribedChannelIds = userSubscriptions.Blogs.SelectMany(v => v.Channels) .Where(v => v.AcceptedPrice >= v.Price) .Select(v => v.ChannelId) .Distinct() .ToList(); } freeAccessChannelIds = userSubscriptions.FreeAccessChannelIds.Distinct().ToList(); } var userAccessSignatures = await this.getUserAccessSignatures.HandleAsync( new GetUserAccessSignaturesQuery(query.Requester, query.RequestedUserId, creatorChannelIds, subscribedChannelIds, freeAccessChannelIds)); return(new UserState( userAccessSignatures, accountSettings, blog, userSubscriptions)); }