/// <summary> /// Gets whether subscriptions exist in the Episerver Social subscription repository that match a filter. /// </summary> /// <param name="filter"></param> /// <returns>Whether subscriptions exist.</returns> /// <exception cref="SocialRepositoryException">Thrown if there are any issues sending the request to the /// Episerver Social subscription repository.</exception> public bool Exist(PageSubscriptionFilter filter) { var subscriptionFilter = AdaptSubscriptionFilter(filter); try { return(this.subscriptionService.Get( new Criteria <SubscriptionFilter> { PageInfo = new PageInfo { PageSize = 0 }, Filter = subscriptionFilter } ).HasMore); } catch (SocialAuthenticationException ex) { throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.", ex); } catch (MaximumDataSizeExceededException ex) { throw new SocialRepositoryException("The application request was deemed too large for Episerver Social.", ex); } catch (SocialCommunicationException ex) { throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex); } catch (SocialException ex) { throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex); } }
/// <summary> /// Adapt a PageSubscriptionFilter to a SubscriptionFilter /// </summary> /// <param name="filter">The PageSubscriptionFilter </param> /// <returns>The SubscriptionFilter</returns> private SubscriptionFilter AdaptSubscriptionFilter(PageSubscriptionFilter filter) { return(new SubscriptionFilter { Subscriber = !string.IsNullOrWhiteSpace(filter.Subscriber) ? Reference.Create(filter.Subscriber) : Reference.Empty, Target = !string.IsNullOrWhiteSpace(filter.Target) ? Reference.Create(filter.Target) : Reference.Empty, }); }
/// <summary> /// Set the block view model property indicating whether the current user is subscribed to the current page. /// </summary> /// <param name="blockViewModel">The subscription block view model.</param> private void SetUserSubscribedToPage(SubscriptionBlockViewModel blockViewModel) { try { var filter = new PageSubscriptionFilter { Subscriber = _userRepository.GetUserId(User), Target = _pageRepository.GetPageId(blockViewModel.CurrentLink) }; if (_subscriptionRepository.Exist(filter)) { blockViewModel.UserSubscribedToPage = true; } else { blockViewModel.UserSubscribedToPage = false; } } catch (SocialRepositoryException ex) { blockViewModel.Messages.Add(new MessageViewModel(ex.Message, ErrorMessage)); } }