Пример #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)));
        }
Пример #2
0
 public ActionResult Unsubscribe(SubscriptionFormViewModel formViewModel) => HandleAction(ActionUnsubscribe, formViewModel);