示例#1
0
        // GET: /<controller>/
        public async Task <IActionResult> IndexAsync(long id, CancellationToken token)
        {
            var query  = new QuestionDataByIdQuery(id);
            var retVal = await _queryBus.QueryAsync(query, token);

            if (retVal == null)
            {
                return(NotFound());
            }
            ViewBag.title           = _localizer["Title", retVal.Course];
            ViewBag.metaDescription = _localizer["Description", retVal.Course];

            if (!retVal.Answers.Any())
            {
                return(View("Index"));
            }
            var jsonLd = new QAPage()
            {
                MainEntity = new Question
                {
                    DateCreated = retVal.Create,
                    Author      = new Person
                    {
                        Name = retVal.User.Name,
                        //Image = retVal.User.Image
                    },
                    Name            = retVal.Text,
                    Text            = retVal.Text,
                    AnswerCount     = retVal.Answers.Count(),
                    SuggestedAnswer = new Values <IAnswer, IItemList>(retVal.Answers.Select((s, i) =>
                                                                                            new Answer
                    {
                        Text        = s.Text,
                        DateCreated = s.Create,
                        Author      = new Person
                        {
                            Name = s.User.Name
                        },
                        Url = new Uri(Url.RouteUrl(SeoTypeString.Question, new { id }, "https", null, $"answer-{i}"))
                    })),
                }
            };

            ViewBag.jsonLd = jsonLd;

            return(View("Index"));
        }
示例#2
0
        public async Task <ActionResult <QuestionDetailDto> > GetQuestionAsync(long id,
                                                                               [FromServices] IQueryBus bus,
                                                                               [FromServices] IUrlBuilder urlBuilder, CancellationToken token)
        {
            var query  = new QuestionDataByIdQuery(id);
            var retVal = await bus.QueryAsync(query, token);

            if (retVal == null)
            {
                return(NotFound());
            }
            retVal.User.Image = urlBuilder.BuildUserImageEndpoint(retVal.User.Id, retVal.User.Image);

            foreach (var answer in retVal.Answers)
            {
                answer.User.Image = urlBuilder.BuildUserImageEndpoint(answer.User.Id, answer.User.Image);
            }
            return(retVal);
        }
示例#3
0
 public async Task QuestionDataByIdQuery_Ok()
 {
     var query = new QuestionDataByIdQuery(10626);
     var _     = await fixture.QueryBus.QueryAsync(query, default);
 }