From 1fa79772badaec366fa2f90613fd3948c8242562 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 4 Jan 2021 16:02:07 +0330 Subject: [PATCH] #59 fullurl + fulltitle for pages related to poems --- .../Services/Implementation/GanjoorService.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index e753ea33..14fe1703 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -946,21 +946,30 @@ namespace RMuseum.Services.Implementation } } await _context.SaveChangesAsync(); + - var orphanPages = await _context.GanjoorPages.Where(p => p.ParentId != null && p.FullUrl == null).ToListAsync(); + var orphanPages = await _context.GanjoorPages.Include(p => p.Poem).Where(p => p.FullUrl == null).ToListAsync(); foreach(var page in orphanPages) { string fullUrl = page.UrlSlug; string fullTitle = page.Title; - GanjoorPage parent = await _context.GanjoorPages.Where(p => p.Id == page.ParentId).SingleAsync(); - while(parent != null) + if(page.GanjoorPageType == GanjoorPageType.PoemPage) { - fullUrl = parent.UrlSlug + "/" + fullUrl; - fullTitle = parent.Title + " » " + fullTitle; - parent = parent.ParentId == null ? null : await _context.GanjoorPages.Where(p => p.Id == parent.ParentId).SingleAsync(); + fullTitle = page.Poem.FullTitle; + fullUrl = page.Poem.FullUrl; + } + else + if(page.ParentId != null) + { + GanjoorPage parent = await _context.GanjoorPages.Where(p => p.Id == page.ParentId).SingleAsync(); + while (parent != null) + { + fullUrl = parent.UrlSlug + "/" + fullUrl; + fullTitle = parent.Title + " » " + fullTitle; + parent = parent.ParentId == null ? null : await _context.GanjoorPages.Where(p => p.Id == parent.ParentId).SingleAsync(); + } } - page.FullUrl = fullUrl; page.FullTitle = fullTitle;