Exemple #1
0
        /// <summary>
        /// Handle subscribe/unsubscribe actions.
        /// </summary>
        /// <param name="actionName">The action.</param>
        /// <param name="formViewModel">The form view model.</param>
        /// <returns>The action result.</returns>
        private ActionResult HandleAction(string actionName, SubscriptionFormViewModel formViewModel)
        {
            var subscription = new PageSubscription
            {
                Subscriber = _userRepository.GetUserId(User),
                Target     = _pageRepository.GetPageId(formViewModel.CurrentLink)
            };

            try
            {
                if (actionName == ActionSubscribe)
                {
                    _subscriptionRepository.Add(subscription);
                }
                else
                {
                    _subscriptionRepository.Remove(subscription);
                }
                AddMessage(MessageKey, new MessageViewModel(SubmitSuccessMessage, SuccessMessage));
            }
            catch (SocialRepositoryException ex)
            {
                AddMessage(MessageKey, new MessageViewModel(ex.Message, ErrorMessage));
            }

            return(Redirect(UrlResolver.Current.GetUrl(formViewModel.CurrentLink)));
        }
Exemple #2
0
        /// <summary>
        /// Adds a subscription to the Episerver Social Framework.
        /// </summary>
        /// <param name="subscription">The subscription to add.</param>
        /// <exception cref="SocialRepositoryException">Thrown if there are any issues sending the request to the
        /// Episerver Social Framework.</exception>
        public void Add(PageSubscription subscription)
        {
            var newSubscription = AdaptSubscription(subscription);

            try
            {
                this.subscriptionService.Add(newSubscription);
            }
            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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Removes a subscription from the Episerver Social subscription repository.
        /// </summary>
        /// <param name="subscription">The subscription to remove.</param>
        /// <exception cref="SocialRepositoryException">Thrown if there are any issues sending the request to the
        /// Episerver Social cloud subscription repository.</exception>
        public void Remove(PageSubscription subscription)
        {
            var removeSubscription = AdaptSubscription(subscription);

            try
            {
                this.subscriptionService.Remove(
                    new Criteria <SubscriptionFilter>
                {
                    Filter = new SubscriptionFilter
                    {
                        Subscriber = removeSubscription.Subscriber,
                        Target     = removeSubscription.Target,
                        Type       = removeSubscription.Type
                    }
                }
                    );
            }
            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);
            }
        }
Exemple #4
0
 /// <summary>
 /// Adapt the application PageSubscription to the Episerver Social Subscription
 /// </summary>
 /// <param name="subscription">The application's PageSubscription.</param>
 /// <returns>The Episerver Social Subscription.</returns>
 private Subscription AdaptSubscription(PageSubscription subscription)
 {
     return(new Subscription(Reference.Create(subscription.Subscriber),
                             Reference.Create(subscription.Target)));
 }