public static IHtmlContent RenderMarkdown(this IHtmlHelper htmlHelper, string markdown) { return(new HtmlString(MarkdownConfig.Transform(markdown))); }
public async Task <CreateOrganizationForTechnologyResponse> Post(CreateOrganizationForTechnology request) { if (request.TechnologyId == null && request.TechStackId == null) { throw new ArgumentNullException(nameof(request.TechnologyId)); } var user = GetUser(); var userId = user.GetUserId(); var type = request.TechnologyId != null ? typeof(Technology) : typeof(TechnologyStack); var technology = request.TechnologyId != null ? Db.SingleById <Technology>(request.TechnologyId.Value) : null; var techstack = request.TechStackId != null ? Db.SingleById <TechnologyStack>(request.TechStackId.Value) : null; if (technology == null && techstack == null) { throw HttpError.NotFound(type.Name + " does not exist"); } var name = technology?.Name ?? techstack?.Name; var alreadyLinked = technology?.CommentsPostId != null || techstack?.CommentsPostId != null; if (alreadyLinked) { throw HttpError.Conflict($"{name} {type.Name} Post has already been linked"); } var id = technology?.Id ?? techstack.Id; var techOrgId = technology?.OrganizationId ?? techstack?.OrganizationId; var techSlug = technology?.Slug ?? techstack?.Slug; var techRoute = techstack != null ? "stacks" : "tech"; var organization = techOrgId == null ? Db.Single <Organization>(x => x.Slug == techSlug) : Db.SingleById <Organization>(techOrgId); using (var trans = Db.OpenTransaction()) { var postTitle = $"{name} Page Comments"; var postContent = $"### Comments for [{name} {type.Name}](/{techRoute}/{techSlug}) page"; var now = DateTime.Now; if (organization == null) { var description = technology?.Description ?? techstack?.Description; organization = new Organization { Name = name, Slug = techSlug, Description = description, DescriptionHtml = MarkdownConfig.Transform(description), PostTypes = new [] { PostType.Announcement.ToString(), PostType.Post.ToString(), PostType.Showcase.ToString(), }, RefId = id, RefSource = type.Name, RefUrn = $"urn:{type.Name}:{id}", Created = now, CreatedBy = user.UserName, Modified = now, ModifiedBy = user.UserName, }; organization.Id = (int)await Db.InsertAsync(organization, selectIdentity : true); } var post = new Post { OrganizationId = organization.Id, Type = PostType.Post, Title = postTitle, Slug = postTitle.GenerateSlug(), Content = postContent, ContentHtml = $"<div class='gfm ssfm'>{MarkdownConfig.Transform(postContent)}</div>", RefId = organization.RefId, RefSource = organization.RefSource, RefUrn = organization.RefUrn, Created = now, CreatedBy = user.UserName, Modified = now, ModifiedBy = user.UserName, Hidden = now, HiddenBy = "webstacks", UserId = userId, UpVotes = 0, Rank = 0, TechnologyIds = technology != null ? new[] { (int)technology.Id } : null, }; post.Id = await Db.InsertAsync(post, selectIdentity : true); if (technology != null) { await Db.UpdateOnlyAsync(() => new Technology { OrganizationId = organization.Id, CommentsPostId = post.Id, }, where : x => x.Id == technology.Id); } else { await Db.UpdateOnlyAsync(() => new TechnologyStack { OrganizationId = organization.Id, CommentsPostId = post.Id, }, where : x => x.Id == techstack.Id); } trans.Commit(); SendSystemEmail(nameof(CreateOrganizationForTechnology), $"New {name} {type.Name} Organization was created by {user.UserName} at /{techSlug}"); ClearOrganizationCaches(); ClearPostCaches(); return(new CreateOrganizationForTechnologyResponse { OrganizationId = organization.Id, OrganizationSlug = organization.Slug, CommentsPostId = post.Id, CommentsPostSlug = post.Slug, }); } }