diff --git a/GanjooRazor/Areas/Admin/Pages/CatUtils.cshtml b/GanjooRazor/Areas/Admin/Pages/CatUtils.cshtml index 71b0041b..4d63c435 100644 --- a/GanjooRazor/Areas/Admin/Pages/CatUtils.cshtml +++ b/GanjooRazor/Areas/Admin/Pages/CatUtils.cshtml @@ -188,10 +188,7 @@ ابتدا - حروف قافیه - - - وزن + بخش‌ها @@ -207,10 +204,37 @@ @poem.Excerpt - @poem.RhymeLetters - - - @poem.Rhythm + + + + + + + + @foreach (var s in poem.MainSections) + { + + + + + + } +
+ ابتدا + + وزن اصلی + + قافیه +
+ @s.Excerpt + + @if(s.GanjoorMetre != null) + { + @s.GanjoorMetre.Rhythm + } + + @s.RhymeLetters +
diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 1d374b48..a64e1160 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -398,6 +398,7 @@ namespace RMuseum.Controllers /// /// /// + /// /// [HttpGet] [Route("cat/{id}")] @@ -405,13 +406,13 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task GetCatById(int id, bool poems = true) + public async Task GetCatById(int id, bool poems = true, bool mainSections = false) { var cacheKey = $"cat/byid/{id}/{poems}"; if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetCompleteViewModel cat)) { RServiceResult res = - await _ganjoorService.GetCatById(id, poems); + await _ganjoorService.GetCatById(id, poems, mainSections); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); if (res.Result == null) @@ -430,6 +431,7 @@ namespace RMuseum.Controllers /// /// /// + /// /// [HttpGet] [Route("cat")] @@ -437,13 +439,13 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetCompleteViewModel))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task GetCatByUrl(string url, bool poems = true) + public async Task GetCatByUrl(string url, bool poems = true, bool mainSections = false) { var cacheKey = $"cat/byurl/{url}/{poems}"; if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetCompleteViewModel cat)) { RServiceResult res = - await _ganjoorService.GetCatByUrl(url, poems); + await _ganjoorService.GetCatByUrl(url, poems, mainSections); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); if (res.Result == null) diff --git a/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs b/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs index b412a7ed..54f070d6 100644 --- a/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs +++ b/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs @@ -118,5 +118,11 @@ namespace RMuseum.Models.Ganjoor /// [NotMapped] public bool Modified { get; set; } + + /// + /// excerpt + /// + [NotMapped] + public string Excerpt { get; set; } } } diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemSummaryViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemSummaryViewModel.cs index 02920afc..3b31fa91 100644 --- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemSummaryViewModel.cs +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemSummaryViewModel.cs @@ -26,16 +26,9 @@ public string Excerpt { get; set; } /// - /// Rythm + /// whole poem sections /// - /// مفاعیلن مفاعیلن فعولن - public string Rhythm { get; set; } - - /// - /// rhyme letters - /// - public string RhymeLetters { get; set; } - + public GanjoorPoemSection[] MainSections { get; set; } } } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 5cde47fd..745aceea 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -964,20 +964,22 @@ poet image - + cat by id + - + cat by full url + @@ -7107,6 +7109,11 @@ modified + + + excerpt + + poem translation @@ -8844,15 +8851,9 @@ excerpt text - + - Rythm - - مفاعیلن مفاعیلن فعولن - - - - rhyme letters + whole poem sections @@ -11139,20 +11140,22 @@ - + get cat by id + - + get cat by url + @@ -13892,20 +13895,22 @@ - + get cat by url + - + get cat by id + diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index c534edd9..3fe4a966 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -49,16 +49,18 @@ namespace RMuseum.Services /// /// /// + /// /// - Task> GetCatById(int id, bool poems = false); + Task> GetCatById(int id, bool poems = false, bool mainSections = false); /// /// get cat by url /// /// /// + /// /// - Task> GetCatByUrl(string url, bool poems = false); + Task> GetCatByUrl(string url, bool poems = false, bool mainSections = false); /// /// get page by url diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 95533a04..d74314f4 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -154,8 +154,9 @@ namespace RMuseum.Services.Implementation /// /// /// + /// /// - public async Task> GetCatByUrl(string url, bool poems = false) + public async Task> GetCatByUrl(string url, bool poems = false, bool mainSections = false) { // /hafez/ => /hafez : if (url.LastIndexOf('/') == url.Length - 1) @@ -165,7 +166,7 @@ namespace RMuseum.Services.Implementation var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == url).AsNoTracking().SingleOrDefaultAsync(); if (cat == null) return new RServiceResult(null); - return await GetCatById(cat.Id, poems); + return await GetCatById(cat.Id, poems, mainSections); } /// @@ -173,8 +174,9 @@ namespace RMuseum.Services.Implementation /// /// /// + /// /// - public async Task> GetCatById(int id, bool poems = false) + public async Task> GetCatById(int id, bool poems = false, bool mainSections = false) { var cat = await _context.GanjoorCategories.Include(c => c.Poet).Include(c => c.Parent).Where(c => c.Id == id).AsNoTracking().FirstOrDefaultAsync(); if (cat == null) @@ -293,14 +295,34 @@ namespace RMuseum.Services.Implementation Title = p.Title, UrlSlug = p.UrlSlug, Excerpt = _context.GanjoorVerses.Where(v => v.PoemId == p.Id && v.VOrder == 1).FirstOrDefault().Text, - Rhythm = p.GanjoorMetre.Rhythm, - RhymeLetters = p.RhymeLetters } ).AsNoTracking().ToListAsync() : null }; + if(poems && mainSections) + { + foreach (var poem in catViewModel.Poems) + { + poem.MainSections = await _context.GanjoorPoemSections.AsNoTracking().Include(s => s.GanjoorMetre).Where(s => s.PoemId == poem.Id && s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.First).OrderBy(s => s.Index).ToArrayAsync(); + foreach (var section in poem.MainSections) + { + section.Excerpt = (await _context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == section.PoemId && + ( + (section.VerseType == VersePoemSectionType.First && v.SectionIndex1 == section.Index) + || + (section.VerseType == VersePoemSectionType.Second && v.SectionIndex2 == section.Index) + || + (section.VerseType == VersePoemSectionType.Third && v.SectionIndex3 == section.Index) + || + (section.VerseType == VersePoemSectionType.Forth && v.SectionIndex4 == section.Index) + ) + ).OrderBy(v => v.VOrder).FirstOrDefaultAsync()).Text; + } + } + } + return new RServiceResult ( new GanjoorPoetCompleteViewModel() @@ -1197,15 +1219,14 @@ namespace RMuseum.Services.Implementation string searchConditions = null; if (!string.IsNullOrEmpty(term)) { - /// You need to run this scripts manually on the database before using this method: - /// - /// CREATE FULLTEXT CATALOG [GanjoorHtmlCommentTextCatalog] WITH ACCENT_SENSITIVITY = OFF AS DEFAULT - /// - /// CREATE FULLTEXT INDEX ON [dbo].[GanjoorComments]( - /// [HtmlComment] LANGUAGE 'English') - /// KEY INDEX [PK_GanjoorComments]ON ([GanjoorHtmlCommentTextCatalog], FILEGROUP [PRIMARY]) - /// WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM) - /// + /* You need to run this scripts manually on the database before using this method: + CREATE FULLTEXT CATALOG [GanjoorHtmlCommentTextCatalog] WITH ACCENT_SENSITIVITY = OFF AS DEFAULT + + CREATE FULLTEXT INDEX ON [dbo].[GanjoorComments]( + [HtmlComment] LANGUAGE 'English') + KEY INDEX [PK_GanjoorComments]ON ([GanjoorHtmlCommentTextCatalog], FILEGROUP [PRIMARY]) + WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM) + */ term = term.Replace("‌", " ");//replace zwnj with space if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1))