예제 #1
0
        /// <summary>
        /// This view will be rendered if answer is in the URL string.
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> MyContent()
        {
            var culture     = this.Culture;
            var requestPath = this.RequestPathNoCulture;
            // Now try to parse the request path into known words.
            var commonStrings = _resourcesService.GetCommonStrings(culture);
            var answer        = LinkingHelper.ParseUrlToAnswer(commonStrings, requestPath);

            // Were we able to parse?
            if (answer == null)
            {
                return(RedirectToAction("Index"));
            }
            // Let's try to find that answer
            answer = await _answerService.FindExact(answer.LeftWord, answer.RightWord, answer.Phrase);

            // Go to home index if not found
            if (answer == null)
            {
                return(RedirectToAction("Index"));
            }
            // Get data
            var answerDetails = FillInDetails(answer, _answerDescriptionService, _userService, _voteService, _resourcesService,
                                              culture, _appSettings.Value.FullDomainAddress);

            // Do a bit more playing with data
            answerDetails.EnableFacebookSharing = _appSettings.Value.EnableFacebookSharing;

            answerDetails.DebugReactControls = ReadUrlParameterAsBoolean(DEBUG_REACTJS_URL_PARAMETER_NAME);

            return(View(answerDetails));
        }
예제 #2
0
        /// <summary>
        /// Fill in answer details for content page.
        /// Reuse the logic between controllers. Also used by AnswerActionController.
        /// </summary>
        /// <param name="answer"></param>
        /// <param name="answerDescriptionService"></param>
        /// <param name="userManager"></param>
        /// <param name="voteService"></param>
        /// <param name="resourcesService"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public static AnswerDetailsDto FillInDetails(AnswerDto answer, IAnswerDescriptionService answerDescriptionService,
                                                     IUserService userService, IVoteService voteService, IResourcesService resourcesService, string culture, string fullDomainName)
        {
            // Load answer descriptions
            // Have to do the list otherwise setting description.UserDisplayName below will not work.
            var searchResult = answerDescriptionService.FindByAnswerId(answer.Id);
            List <AnswerDescriptionDto> descriptions = searchResult == null ? null : searchResult.ToList();

            // Set the username for each description
            if (descriptions != null)
            {
                foreach (var description in descriptions)
                {
                    GetUserDisplayName(description, userService);
                }
            }

            // Fill in result
            var data = new AnswerDetailsDto()
            {
                Answer        = answer,
                CommonStrings = resourcesService.GetCommonStrings(culture),
                Descriptions  = descriptions,
                NumberVotes   = voteService.CountAnswerVotes(answer.Id)
            };

            GetUserDisplayName(data.Answer, userService);

            // Fill in link to this page and other usefull data.
            data.ThisAnswerLink            = LinkingHelper.ConvertAnswerToUrlWithCulture(culture, data.CommonStrings, answer);
            data.ThisAnswerFullLink        = fullDomainName.EndsWith("/") ? fullDomainName.Substring(0, fullDomainName.Length - 1) : fullDomainName + data.ThisAnswerLink;
            data.ThisAnswerText            = LinkingHelper.ConvertAnswerToText(data.CommonStrings, answer);
            data.ThisAnswerFullLinkEscaped = System.Uri.EscapeDataString(data.ThisAnswerFullLink);

            return(data);
        }