From 47c076cf3a0e857ed168c1354a27bd52d8645500 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 21 Jul 2024 10:43:19 +0330 Subject: [PATCH] #445 tajik poem services --- RMuseum/Models/Ganjoor/GanjoorTajikPoem.cs | 5 + RMuseum/Models/Ganjoor/GanjoorTajikPoet.cs | 2 +- RMuseum/Models/Ganjoor/GanjoorTajikVerse.cs | 11 +++ RMuseum/RMuseum.xml | 39 +++++++- RMuseum/Services/IGanjoorService.cs | 14 +++ .../GanjoorService-Transilerate.cs | 7 +- .../GanjoorService_Tajik.cs | 95 +++++++++++++++++++ 7 files changed, 169 insertions(+), 4 deletions(-) diff --git a/RMuseum/Models/Ganjoor/GanjoorTajikPoem.cs b/RMuseum/Models/Ganjoor/GanjoorTajikPoem.cs index 043167d1..47eb0a29 100644 --- a/RMuseum/Models/Ganjoor/GanjoorTajikPoem.cs +++ b/RMuseum/Models/Ganjoor/GanjoorTajikPoem.cs @@ -11,6 +11,11 @@ namespace RMuseum.Models.Ganjoor [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public int Id { get; set; } + /// + /// cat id + /// + public int CatId { get; set; } + /// /// title /// diff --git a/RMuseum/Models/Ganjoor/GanjoorTajikPoet.cs b/RMuseum/Models/Ganjoor/GanjoorTajikPoet.cs index 949a0466..f6fce380 100644 --- a/RMuseum/Models/Ganjoor/GanjoorTajikPoet.cs +++ b/RMuseum/Models/Ganjoor/GanjoorTajikPoet.cs @@ -14,7 +14,7 @@ namespace RMuseum.Models.Ganjoor /// /// tajik nick name /// - public string TajikNickName { get; set; } + public string TajikNickname { get; set; } /// /// additional descripion or note in Tajik diff --git a/RMuseum/Models/Ganjoor/GanjoorTajikVerse.cs b/RMuseum/Models/Ganjoor/GanjoorTajikVerse.cs index 8e8798a7..d67fc60e 100644 --- a/RMuseum/Models/Ganjoor/GanjoorTajikVerse.cs +++ b/RMuseum/Models/Ganjoor/GanjoorTajikVerse.cs @@ -11,6 +11,17 @@ namespace RMuseum.Models.Ganjoor [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] public int Id { get; set; } + /// + /// poem_id + /// + public int PoemId { get; set; } + + /// + /// vorder + /// + public int VOrder { get; set; } + + /// /// tajik text /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index e774747a..10216d04 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -9780,6 +9780,11 @@ id + + + cat id + + title @@ -9800,7 +9805,7 @@ id - + tajik nick name @@ -9815,6 +9820,16 @@ id + + + poem_id + + + + + vorder + + tajik text @@ -16788,6 +16803,20 @@ transilerate verse data from Persian to Tajiki + + + tajik poets + + + + + + tajik page by url + + + + + translation service implementation @@ -19259,6 +19288,14 @@ + + + tajik page by url + + + + + Get List of poets diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index ab806525..95abd835 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -1472,5 +1472,19 @@ namespace RMuseum.Services /// void Transilerate(); + /// + /// tajik poets + /// + /// + Task> GetTajikPoetsAsync(); + + /// + /// tajik page by url + /// + /// + /// + /// + Task> GetTajikPageByUrlAsync(string url, bool catPoems = false); + } } diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs index e52213ff..d7f126e1 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Transilerate.cs @@ -53,7 +53,9 @@ namespace RMuseum.Services.Implementation GanjoorTajikVerse tajikVerse = new GanjoorTajikVerse() { Id = verse.Id, - TajikText = TajikTransilerator.Transilerate(verse.Text) + PoemId = verse.PoemId, + VOrder = verse.VOrder, + TajikText = TajikTransilerator.Transilerate(verse.Text), }; context.Add(tajikVerse); } @@ -64,6 +66,7 @@ namespace RMuseum.Services.Implementation GanjoorTajikPoem tajikPoem = new GanjoorTajikPoem() { Id = poem.Id, + CatId = poem.CatId, TajikTitle = TajikTransilerator.Transilerate(poem.Title), }; context.Add(tajikPoem); @@ -91,7 +94,7 @@ namespace RMuseum.Services.Implementation GanjoorTajikPoet tajikPoet = new GanjoorTajikPoet() { Id = poet.Id, - TajikNickName = TajikTransilerator.Transilerate(poet.Nickname), + TajikNickname = TajikTransilerator.Transilerate(poet.Nickname), TajikDescription = TajikTransilerator.Transilerate(poet.Description), }; context.Add(tajikPoet); diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService_Tajik.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService_Tajik.cs index 261604f8..6877da0e 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService_Tajik.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService_Tajik.cs @@ -3,6 +3,9 @@ using System; using RMuseum.Models.Ganjoor; using System.Threading.Tasks; using RSecurityBackend.Models.Generic; +using RMuseum.Models.Ganjoor.ViewModels; +using System.Linq; +using Org.BouncyCastle.Asn1.Ocsp; namespace RMuseum.Services.Implementation { @@ -26,5 +29,97 @@ namespace RMuseum.Services.Implementation return new RServiceResult(null, exp.ToString()); } } + + /// + /// tajik page by url + /// + /// + /// + /// + public async Task> GetTajikPageByUrlAsync(string url, bool catPoems = false) + { + try + { + var res = await GetPageByUrl(url, catPoems); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return res; + GanjoorPageCompleteViewModel page = res.Result; + + var tajikPoet = await _context.TajikPoets.AsNoTracking().Where(p => p.Id == page.PoetOrCat.Poet.Id).SingleOrDefaultAsync(); + if (tajikPoet == null) + return new RServiceResult(null, "Ин суханвар ҳануз ба тоҷикӣ дар дастрас нест."); + page.PoetOrCat.Poet.Nickname = tajikPoet.TajikNickname; + page.PoetOrCat.Poet.Description = tajikPoet.TajikDescription; + var tajikCat = await _context.TajikCats.AsNoTracking().Where(c => c.Id == page.PoetOrCat.Cat.Id).SingleAsync(); + page.PoetOrCat.Cat.Title = tajikCat.TajikTitle; + page.PoetOrCat.Cat.Description = tajikCat.TajikDescription; + foreach (var parent in page.PoetOrCat.Cat.Ancestors) + { + var tajikParent = await _context.TajikCats.AsNoTracking().Where(c => c.Id == parent.Id).SingleAsync(); + parent.Title = tajikParent.TajikTitle; + parent.Description = tajikParent.TajikDescription; + } + foreach (var child in page.PoetOrCat.Cat.Children) + { + var tajikChild = await _context.TajikCats.AsNoTracking().Where(c => c.Id == child.Id).SingleAsync(); + child.Title = tajikChild.TajikTitle; + child.Description = tajikChild.TajikDescription; + } + if(page.PoetOrCat.Cat.Next != null) + { + var nextCat = await _context.TajikCats.AsNoTracking().Where(c => c.Id == page.PoetOrCat.Cat.Next.Id).SingleAsync(); + page.PoetOrCat.Cat.Next.Title = nextCat.TajikTitle; + } + if (page.PoetOrCat.Cat.Previous != null) + { + var preCat = await _context.TajikCats.AsNoTracking().Where(c => c.Id == page.PoetOrCat.Cat.Previous.Id).SingleAsync(); + page.PoetOrCat.Cat.Previous.Title = preCat.TajikTitle; + } + + if (page.PoetOrCat.Cat.Poems != null) + { + var tajikPoems = await _context.TajikPoems.AsNoTracking().Where(p => p.CatId == page.PoetOrCat.Cat.Id).ToListAsync(); + foreach (var poem in page.PoetOrCat.Cat.Poems) + { + var tajikPoem = tajikPoems.Where(p => p.Id == poem.Id).SingleOrDefault(); + if(tajikPoem != null) + { + poem.Title = tajikPoem.TajikTitle; + } + } + } + + if(page.Poem != null) + { + var tajikPoem = await _context.TajikPoems.AsNoTracking().Where(p => p.Id == page.Poem.Id).SingleAsync(); + page.Poem.Title = tajikPoem.TajikTitle; + page.Poem.PlainText = tajikPoem.TajikPlainText; + page.Poem.HtmlText = tajikPoem.TajikHtmlText; + + var tajikVerses = await _context.TajikVerses.AsNoTracking().Where(v => v.PoemId == page.Poem.Id).OrderBy(v => v.VOrder).ToListAsync(); + foreach( var verse in page.Poem.Verses) + { + verse.Text = tajikVerses.Where(v => v.VOrder == verse.VOrder).SingleOrDefault().TajikText; + } + + if(page.Poem.Next != null) + { + var nextPoem = await _context.TajikPoems.AsNoTracking().Where(p => p.Id == page.Poem.Next.Id).SingleAsync(); + page.Poem.Next.Title = nextPoem.TajikTitle; + + } + if (page.Poem.Previous != null) + { + var prePoem = await _context.TajikPoems.AsNoTracking().Where(p => p.Id == page.Poem.Previous.Id).SingleAsync(); + page.Poem.Next.Title = prePoem.TajikTitle; + } + } + return new RServiceResult(page); + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } } } \ No newline at end of file