public ContentViewModel Create(ContentRequest request) { Authorized(); var content = new Content(); content.Title = request.Title; content.Body = request.Body; content.HtmlBody = Markdown.Encode(content.Body); content.UserId = user.Id; content.Type = request.Type; var id = ContentApi.Insert(content); TagManager.SetTagsForContent(id, request.Tags); if (request.ParentId != null) { ContentApi.Relate(request.ParentId.Value, id); } return(ContentApi.Select(id).AsViewModel() .WithChildren() .WithChildrenCount() .WithTags()); }
public ContentViewModel Create(ContentRequest request) { Authorized(); var content = new Content(); content.Title = request.Title; content.Body = request.Body; content.HtmlBody = Markdown.Encode(content.Body); content.UserId = user.Id; content.Type = request.Type; var id = ContentApi.Insert(content); TagManager.SetTagsForContent(id, request.Tags); if (request.ParentId != null) { ContentApi.Relate(request.ParentId.Value, id); } var item = ContentApi.Select(id).AsViewModel() .WithChildren() .WithChildrenCount() .WithUser() .WithTags(); Searcher.Instance.Index(new Searchable() { Id = id, Type = item.Type, Title = item.Title, Body = item.Body, Username = item.User.DisplayName }); ContentApi.MarkAsIndexed(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" })); }