From 2ac7a8f9b3acc0c7e5c474b242647943a0015a84 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 21 Jul 2024 15:30:56 +0330 Subject: [PATCH] #445 PrepareTajikPoetHtmlTextAsync --- .../GanjoorService-Transilerate.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs index 679bfb06..dab8e5f0 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs @@ -8,6 +8,7 @@ using RSecurityBackend.Services.Implementation; using RMuseum.Utils; using RMuseum.Models.Ganjoor; using NAudio.Gui; +using System.Threading.Tasks; namespace RMuseum.Services.Implementation { @@ -140,6 +141,15 @@ namespace RMuseum.Services.Implementation poet.TajikDescription = LanguageUtils.CleanTextForTransileration(poet.TajikDescription); context.Update(poet); await context.SaveChangesAsync(); + + var poetPage = await context.GanjoorPages.AsNoTracking().Where(p => p.GanjoorPageType == GanjoorPageType.PoetPage && p.PoetId == poet.Id).SingleAsync(); + GanjoorTajikPage page = new GanjoorTajikPage() + { + Id = poetPage.Id, + TajikHtmlText = await PrepareTajikPoetHtmlTextAsync(context, poet), + }; + context.Add(page); + await context.SaveChangesAsync(); } var cats = await context.TajikCats.ToListAsync(); @@ -178,6 +188,33 @@ namespace RMuseum.Services.Implementation }); } + private async Task PrepareTajikPoetHtmlTextAsync(RMuseumDbContext context, GanjoorTajikPoet poet) + { + + string[] lines = poet.TajikDescription.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries); + string html = ""; + foreach (var line in lines) + { + html += $"

{line}

"; + } + var poetCat = await context.GanjoorCategories.AsNoTracking().Where(c => c.PoetId == poet.Id && c.ParentId == null).SingleAsync(); + var subCats = await context.GanjoorCategories.AsNoTracking().Where(c => c.ParentId == poetCat.Id).OrderBy(p => p.Id).ToListAsync(); + foreach (var subCat in subCats) + { + var tajikCat = await context.TajikCats.AsNoTracking().Where(t => t.Id == subCat.Id).SingleAsync(); + html += $"

{LanguageUtils.CleanTextForTransileration(tajikCat.TajikTitle)}

"; + } + + var catPoems = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == poetCat.Id).OrderBy(p => p.Id).ToListAsync(); + var tajikPoems = await context.TajikPoems.AsNoTracking().Where(p => p.CatId == poetCat.Id).OrderBy(p => p.Id).ToListAsync(); + foreach (var catPoem in catPoems) + { + var tajikPoem = tajikPoems.Where(p => p.Id == catPoem.Id).Single(); + html += $"

{LanguageUtils.CleanTextForTransileration(tajikPoem.TajikTitle)}

"; + } + return html; + } + }