From 7bfc50e1e9491d7e4967c3a7b95b366c60c8b9ac Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 15 Nov 2021 18:47:09 +0330 Subject: [PATCH] #241 fixing bugs and improvements --- .../GanjoorService-Partials/GanjoorService-Maintenance.cs | 5 +++++ .../GanjoorService-Partials/GanjoorService-RelatedPoems.cs | 4 ++-- RMuseum/Services/Implementation/GanjoorService.cs | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs index 7ff823a2..233a563c 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Maintenance.cs @@ -58,6 +58,11 @@ namespace RMuseum.Services.Implementation context.GanjoorPoems.Update(poem); await context.SaveChangesAsync(); } + + if(poem.GanjoorMetreId != null && !string.IsNullOrEmpty(poem.RhymeLetters)) + { + await _UpdateRelatedPoems(context, (int)poem.GanjoorMetreId, poem.RhymeLetters); + } } } } diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs index 73d92221..6803dde5 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedPoems.cs @@ -54,7 +54,7 @@ namespace RMuseum.Services.Implementation int metreId = (int)poem.GanjoorMetreId; string rhyme = poem.RhymeLetters; - var relatedPoems = context.GanjoorPoems.AsNoTracking().Include(p => p.Cat).ThenInclude(c => c.Poet) + var relatedPoems = await context.GanjoorPoems.AsNoTracking().Include(p => p.Cat).ThenInclude(c => c.Poet) .Where(p => p.GanjoorMetreId == metreId && @@ -62,7 +62,7 @@ namespace RMuseum.Services.Implementation && p.Id != poemId ) - .OrderBy(p => p.Cat.Poet.BirthYearInLHijri).ThenBy(p => p.Cat.PoetId); + .OrderBy(p => p.Cat.Poet.BirthYearInLHijri).ThenBy(p => p.Cat.PoetId).ToListAsync(); List ganjoorCachedRelatedPoems = new List(); int r = 0; diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 83026a2e..6782cee0 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -3004,6 +3004,8 @@ namespace RMuseum.Services.Implementation if(oldMetreId != dbPoem.GanjoorMetreId || oldRhymeLetters != dbPoem.RhymeLetters) { + await _context.SaveChangesAsync(); + if (oldMetreId != null && !string.IsNullOrEmpty(oldRhymeLetters)) await _UpdateRelatedPoems(_context, (int)oldMetreId, oldRhymeLetters);