public virtual async Task UpdateAsync( Material material, string tags, CategoryCached category) { IHtmlDocument doc = new HtmlParser().Parse(material.Text); material.Text = sanitizer.Sanitize(doc); var generator = categoriesCache.GetMaterialsPreviewGenerator(category.MaterialsPreviewGeneratorName); material.Preview = generator(doc, materialsOptions.PreviewLength); switch (category.MaterialsSubTitleInputType) { case MaterialsSubTitleInputType.Manual: material.SubTitle = SimpleHtmlToText.ClearTags(sanitizer.Sanitize(material.SubTitle)); break; case MaterialsSubTitleInputType.Auto: material.SubTitle = MakeSubTitle.Do(doc, materialsOptions.SubTitleLength); break; default: material.SubTitle = null; break; } await db.UpdateAsync(material); await tagsManager.MaterialCreateAndSetTagsAsync(material, tags); }
public virtual async ValueTask UpdateAsync( 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; default: material.SubTitle = null; break; } await db.UpdateAsync(material); await tagsManager.MaterialCreateAndSetTagsAsync(material, tags); }
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 Material SeedMaterial( Category category, string title, int commentsCount, string firstLine, string lineElement, LinesCount linesCount) { var publishDate = dataContainer.IterateCommentPublishDate(); int linesCountCurrent = ran.Next(linesCount.Min, linesCount.Max); int id = dataContainer.NextMaterialId(); Material material = new Material { Id = id, Title = title, Text = MakeSeedText(lineElement, 8, linesCountCurrent, firstLine), AuthorId = dataContainer.GetRandomUserId(), CategoryId = category.Id, PublishDate = publishDate, LastActivity = publishDate, SortNumber = id }; switch (category.MaterialsSubTitleInputType) { case MaterialsSubTitleInputType.Manual: material.SubTitle = "Описание материала: " + material.Title; break; case MaterialsSubTitleInputType.Auto: material.SubTitle = MakeSubTitle.Do(new HtmlParser().Parse(material.Text), MaterialSubTitleLength); break; } if (commentsCount > 0) { IList <Comment> comments = MakeComments(material, commentsCount); //Comment last = comments.OrderByDescending(x=>x.PublishDate).First(); //material.SetLastComment(last); material.LastActivity = comments.OrderByDescending(x => x.PublishDate).First().PublishDate; material.CommentsCount = comments.Count; dataContainer.Comments.AddRange(comments); } dataContainer.Materials.Add(material); return(material); }