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 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); }
private void Update() { var content = ContentApi.NeedIndexing(); var vms = content.Select(c => c.AsViewModel().WithUser()); Searcher.Instance.Index(vms.Select(c => new Searchable() { Id = c.Id, Title = c.Title, Body = c.Body, Type = c.Type, Username = c.User.DisplayName })); foreach (var c in content) { ContentApi.MarkAsIndexed(c.Id); } }