예제 #1
0
        public ContentViewModel Update(ContentRequest request)
        {
            Authorized();

            if (request.ContentId == null)
            {
                throw new ArgumentNullException(nameof(request.ContentId));
            }

            var userId = user?.Id;

            if (userId == null)
            {
                throw new ArgumentNullException(nameof(request), "User must be set to update an answer");
            }

            TagManager.SetTagsForContent((int)request.ContentId, request.Tags);

            var htmlBody = Markdown.Encode(request.Body);

            ContentApi.Update(request.ContentId.Value, request.Title, request.Body, htmlBody, (int)userId);

            return(ContentApi.Select(request.ContentId.Value)
                   .AsViewModel()
                   .WithAll());
        }
예제 #2
0
        public ContentViewModel Update(ContentRequest request)
        {
            Authorized();

            if (request.ContentId == null)
            {
                throw new ArgumentNullException(nameof(request.ContentId));
            }

            var userId = user?.Id;

            if (userId == null)
            {
                throw new ArgumentNullException(nameof(request), "User must be set to update an answer");
            }

            TagManager.SetTagsForContent((int)request.ContentId, request.Tags);

            var htmlBody = Markdown.Encode(request.Body);

            ContentApi.Update(request.ContentId.Value, request.Title, request.Body, htmlBody, (int)userId);

            var item = ContentApi.Select(request.ContentId.Value)
                       .AsViewModel()
                       .WithAll();

            Searcher.Instance.Index(new Searchable()
            {
                Id = item.Id, Type = item.Type, Title = item.Title, Body = item.Body, Username = item.User.DisplayName
            });
            ContentApi.MarkAsIndexed(item.Id);
            return(item);
        }
예제 #3
0
        public IActionResult Ask(Content content)
        {
            int id = content.Id;

            if (id == 0)
            {
                content.HtmlBody = Markdown.Encode(content.Body);
                id = ContentApi.Insert(content);
            }
            else
            {
                ContentApi.Update(content.Id, content.Title, content.Body, Markdown.Encode(content.Body));
            }

            return(RedirectToAction("Show", new { Id = id, Response = "Your question was added" }));
        }
예제 #4
0
 public string Answer([FromBody] AnswerRequest req)
 {
     if (req.AnswerId == 0)
     {
         var md       = Markdown.Encode(req.Answer);
         var htmlBody = Markdown.Encode(req.Answer);
         ContentApi.InsertAsChild(req.QuestionId, new Content()
         {
             Type = "answer", Body = req.Answer, UserId = 1, HtmlBody = htmlBody
         });
         return(md);
     }
     else
     {
         var md = Markdown.Encode(req.Answer);
         ContentApi.Update(req.AnswerId, null, req.Answer, md);
         return(md);
     }
 }