private async Task <IPBPublishRecord> CreateOrUpdateContentPostAsync(IPBPublishRecord record, IContentItem item, Site site, IPBPublishConfig config) { if (_contentRender == null) { throw new ArgumentException("No content renderer is registered!"); } var apiClient = _apiClientFactory.GetPublishClient(); if (record.TopicId == 0) { var topic = new TopicCreateModel { Forum = config.ForumId, Title = item.Title, Hidden = !item.IsPublished ? 1 : 0, Post = await _contentRender.RenderHtmlAsync(item, site), Author = int.Parse(config.AuthorId) }; var createdTopic = await apiClient.PostAsync <TopicCreateModel, Topic>("forums/topics", topic); if (createdTopic.FirstPost != null) { record.TopicId = createdTopic.Id; record.PostId = createdTopic.FirstPost.Id; } } else { await apiClient.PostAsync <TopicCreateModel, Topic>( $"forums/topics/{record.TopicId.ToString()}", new TopicCreateModel { Title = item.Title, Hidden = !item.IsPublished ? 1 : 0, Author = int.Parse(config.AuthorId), Forum = config.ForumId, Post = await _contentRender.RenderHtmlAsync(item, site) }); } return(record); }
public async Task <IActionResult> PostAsync(Guid id) { var post = await _contentItemsRepository.GetByIdAsync(id); if (post == null) { return(NotFound()); } var sites = await _sitesRepository.GetByIdsAsync(post.SiteIds); var mainSite = sites.FirstOrDefault(s => s.Id == _options.DefaultMainSiteId) ?? sites.First(); var html = await _contentRender.RenderHtmlAsync(post, mainSite, ContentEntityViewMode.Entity); return(Content(html, "text/html; charset=utf-8")); }