public virtual async ValueTask CreateAsync(Material material, string tags, CategoryCached category) { IHtmlDocument doc = new HtmlParser().Parse(material.Text); material.Text = sanitizerService.Sanitize(doc); material.SettingsJson = material.SettingsJson?.MakeJsonText(); switch (category.MaterialsSubTitleInputType) { case MaterialsSubTitleInputType.Manual: material.SubTitle = SimpleHtmlToText.ClearTags(sanitizerService.Sanitize(material.SubTitle)); break; case MaterialsSubTitleInputType.Auto: material.SubTitle = MakeSubTitle.Do(doc, materialsOptions.SubTitleLength); break; } using (db.BeginTransaction()) { material.Id = await db.InsertWithInt32IdentityAsync(material); await db.Materials.Where(x => x.Id == material.Id).Set(x => x.SortNumber, x => material.Id) .UpdateAsync(); await tagsManager.MaterialCreateAndSetTagsAsync(material, tags); db.CommitTransaction(); } }
public virtual async Task CreateAsync(Material material, string tags, bool isDescriptionEditable = false) { material.Text = sanitizer.Sanitize(material.Text); var(preview, description) = MaterialExtensions.MakePreviewAndDescription(material.Text, materialsOptions.DescriptionLength, materialsOptions.PreviewLength); material.Preview = preview; if (isDescriptionEditable) { material.Description = SimpleHtmlToText.ClearTags(sanitizer.Sanitize(material.Description)); } else { material.Description = description; } /*material.MakePreviewAndDescription(materialsOptions.DescriptionLength, * materialsOptions.PreviewLength);*/ material.Id = await db.InsertWithInt32IdentityAsync(material); await tagsManager.MaterialCreateAndSetTagsAsync(material, tags); }
public virtual async ValueTask CreateAsync( Material material, string tags, CategoryCached category, IReadOnlyDictionary <string, RoleCached> roles) { if (!roles.ContainsKey(RoleNames.Admin) || sanitizerService.SanitizerOptions.SanitizeAdminMaterials) { material.Text = sanitizerService.Sanitize(new HtmlParser().ParseDocument(material.Text)); } material.SettingsJson = material.SettingsJson?.MakeJsonText(); if (category.IsMaterialsSubTitleEditable) { material.SubTitle = SimpleHtmlToText.ClearTags(sanitizerService.Sanitize(material.SubTitle)); } using (db.BeginTransaction()) { material.Id = await db.InsertWithInt32IdentityAsync(material); await db.Materials.Where(x => x.Id == material.Id).Set(x => x.SortNumber, x => material.Id) .UpdateAsync(); await tagsManager.MaterialCreateAndSetTagsAsync(material, tags); db.CommitTransaction(); } }
public virtual async Task CreateAsync( Material material, string tags, bool isDescriptionEditable = false) { material.Text = sanitizer.Sanitize(material.Text); var(preview, description) = MaterialExtensions.MakePreviewAndDescription(material.Text, materialsOptions.DescriptionLength, materialsOptions.PreviewLength); material.Preview = preview; if (isDescriptionEditable) { material.Description = SimpleHtmlToText.ClearTags(sanitizer.Sanitize(material.Description)); } else { material.Description = description; } using (db.BeginTransaction()) { material.Id = await db.InsertWithInt32IdentityAsync(material); await db.Materials.Where(x => x.Id == material.Id).Set(x => x.SortNumber, x => material.Id) .UpdateAsync(); await tagsManager.MaterialCreateAndSetTagsAsync(material, tags); db.CommitTransaction(); } }