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()); }
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); }
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" })); }
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); } }