/// <summary> /// Set any properties the block view model needs for the view to render properly. /// </summary> /// <param name="blockViewModel">The subscription block view model.</param> private void SetBlockViewModelProperties(SubscriptionBlockViewModel blockViewModel) { if (User.Identity.IsAuthenticated) { blockViewModel.ShowSubscriptionForm = true; SetUserSubscribedToPage(blockViewModel); } }
/// <summary> /// Render the subscription block frontend view. /// </summary> /// <param name="currentBlock">The current frontend block instance.</param> /// <returns>The action's result.</returns> public override ActionResult Index(SubscriptionBlock currentBlock) { // Create a subscription block view model to fill the frontend block view var blockViewModel = new SubscriptionBlockViewModel(currentBlock, _pageRouteHelper.PageLink) { //get messages for view Messages = RetrieveMessages(MessageKey) }; // Set Block View Model Properties SetBlockViewModelProperties(blockViewModel); // Render the frontend block view return(PartialView("~/Features/Blocks/SubscriptionBlock/SubscriptionBlock.cshtml", blockViewModel)); }
/// <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)); } }