public IActionResult GetPost(int id)
        {
            var que = _dataService.GetQuestionAllData(id);

            if (que == null)
            {
                return(NotFound());
            }
            var marked = _dataService.IsPostMarked(id);
            var quest  = new JSONObjects.Question
            {
                Url      = Url.Link(nameof(GetPost), que.Id),
                Body     = que.Body,
                Owner    = que.Owner,
                Created  = que.Created,
                Score    = que.Score,
                Title    = que.Title,
                Closed   = que.Closed,
                Marked   = marked,
                NotesUrl = Url.Link(nameof(GetNotes), new { pid = que.Id }),
                Id       = que.Id,
                Answers  = que.Answers.Select(answer => new JSONObjects.Answer
                {
                    Url      = Url.Link(nameof(GetPost), answer.Id),
                    Body     = answer.Body,
                    Owner    = answer.Owner,
                    Created  = answer.Created,
                    Score    = answer.Score,
                    Comments = answer.Comments.Select(comment => new JSONObjects.Comment
                    {
                        Created = comment.Created,
                        Owner   = comment.Owner,
                        Score   = comment.Score,
                        Text    = comment.Text
                    }).ToList()
                }).ToList(),

                Tags     = que.Tags.Select <Tag, string>(tag => tag.Title).ToList(),
                Comments = que.Comments.Select(comment => new JSONObjects.Comment
                {
                    Created = comment.Created,
                    Owner   = comment.Owner,
                    Score   = comment.Score,
                    Text    = comment.Text
                }).ToList()
            };

            return(Ok(quest));
        }
Esempio n. 2
0
        public IActionResult GetQuestion(int id)
        {
            var question = _dataService.GetQuestionAllData(id);

            JSONObjects.Question result = null;
            if (question != null)
            {
                result = new JSONObjects.Question()
                {
                    Url      = Url.Link(nameof(GetPost), question.Id),
                    Body     = question.Body,
                    OwnerUrl = Url.Link(nameof(GetUser), question.OwnerId),
                    Created  = question.Created,
                    Score    = question.Score,
                    Title    = question.Title,
                    Closed   = question.Closed,
                    Answers  = question.Answers.Select(answer => new JSONObjects.Answer
                    {
                        Url      = Url.Link(nameof(GetPost), answer.Id),
                        Body     = answer.Body,
                        OwnerUrl = Url.Link(nameof(GetUser), answer.OwnerId),
                        Created  = answer.Created,
                        Score    = answer.Score,
                        Comments = answer.Comments.Select(comment => new JSONObjects.Comment
                        {
                            Created  = comment.Created,
                            OwnerUrl = Url.Link(nameof(GetUser), comment.OwnerId),
                            Score    = comment.Score,
                            Text     = comment.Text
                        }).ToList()
                    }).ToList(),
                    Tags     = question.Tags.Select <Tag, string>(tag => tag.Title).ToList(),
                    Comments = question.Comments.Select(comment => new JSONObjects.Comment
                    {
                        Created  = comment.Created,
                        OwnerUrl = Url.Link(nameof(GetUser), comment.OwnerId),
                        Score    = comment.Score,
                        Text     = comment.Text
                    }).ToList()
                };
            }
            return(result != null ? (IActionResult)Ok(result) : NotFound());
        }