From 2cf87972a8dd90d3f9a1367551055eed780da9fc Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 19 Apr 2022 20:16:31 +0430 Subject: [PATCH] docs: #306 adding metre 2 to 4 to the correction model --- .../Models/Ganjoor/GanjoorPoemCorrection.cs | 45 ++++++++ RMuseum/Models/Ganjoor/GanjoorPoemSection.cs | 12 +++ .../GanjoorPoemCorrectionViewModel.cs | 45 ++++++++ RMuseum/RMuseum.xml | 100 ++++++++++++++++++ .../GanjoorService-ModeratePoemCorrection.cs | 92 ++++++++++++---- 5 files changed, 275 insertions(+), 19 deletions(-) diff --git a/RMuseum/Models/Ganjoor/GanjoorPoemCorrection.cs b/RMuseum/Models/Ganjoor/GanjoorPoemCorrection.cs index 3b7d632b..000afb87 100644 --- a/RMuseum/Models/Ganjoor/GanjoorPoemCorrection.cs +++ b/RMuseum/Models/Ganjoor/GanjoorPoemCorrection.cs @@ -113,6 +113,51 @@ namespace RMuseum.Models.Ganjoor /// had any effect on poem after moderation? effective in history /// public bool AffectedThePoem { get; set; } + + /// + /// rhythm 2 + /// + public string Rhythm2 { get; set; } + + /// + /// original rhythm 2 + /// + public string OriginalRhythm2 { get; set; } + + /// + /// review result for rhythm 2 + /// + public CorrectionReviewResult Rhythm2Result { get; set; } + + /// + /// rhythm 3 + /// + public string Rhythm3 { get; set; } + + /// + /// original rhythm 3 + /// + public string OriginalRhythm3 { get; set; } + + /// + /// review result for rhythm 3 + /// + public CorrectionReviewResult Rhythm3Result { get; set; } + + /// + /// rhythm 4 + /// + public string Rhythm4 { get; set; } + + /// + /// original rhythm 4 + /// + public string OriginalRhythm4 { get; set; } + + /// + /// review result for rhythm 4 + /// + public CorrectionReviewResult Rhythm4Result { get; set; } } diff --git a/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs b/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs index b1fd501a..f295a3fb 100644 --- a/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs +++ b/RMuseum/Models/Ganjoor/GanjoorPoemSection.cs @@ -95,5 +95,17 @@ namespace RMuseum.Models.Ganjoor /// [NotMapped] public GanjoorCachedRelatedSection[] Top6RelatedSections { get; set; } + + /// + /// old metre id to see it needs refreshing related sections + /// + [NotMapped] + public int? OldGanjoorMetreId { get; set; } + + /// + /// old rhyme letters to see it needs refreshing related sections + /// + [NotMapped] + public string OldRhymeLetters { get; set; } } } diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCorrectionViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCorrectionViewModel.cs index 9c35b386..2d2fd505 100644 --- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCorrectionViewModel.cs +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorPoemCorrectionViewModel.cs @@ -86,5 +86,50 @@ namespace RMuseum.Models.Ganjoor.ViewModels /// review result for rhythm /// public CorrectionReviewResult RhythmResult { get; set; } + + /// + /// rhythm 2 + /// + public string Rhythm2 { get; set; } + + /// + /// original rhythm 2 + /// + public string OriginalRhythm2 { get; set; } + + /// + /// review result for rhythm 2 + /// + public CorrectionReviewResult Rhythm2Result { get; set; } + + /// + /// rhythm 3 + /// + public string Rhythm3 { get; set; } + + /// + /// original rhythm 3 + /// + public string OriginalRhythm3 { get; set; } + + /// + /// review result for rhythm 3 + /// + public CorrectionReviewResult Rhythm3Result { get; set; } + + /// + /// rhythm 4 + /// + public string Rhythm4 { get; set; } + + /// + /// original rhythm 4 + /// + public string OriginalRhythm4 { get; set; } + + /// + /// review result for rhythm 4 + /// + public CorrectionReviewResult Rhythm4Result { get; set; } } } diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index b88a0989..d2071b5a 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -6807,6 +6807,51 @@ had any effect on poem after moderation? effective in history + + + rhythm 2 + + + + + original rhythm 2 + + + + + review result for rhythm 2 + + + + + rhythm 3 + + + + + original rhythm 3 + + + + + review result for rhythm 3 + + + + + rhythm 4 + + + + + original rhythm 4 + + + + + review result for rhythm 4 + + poem format @@ -7050,6 +7095,16 @@ top 6 related sections + + + old metre id to see it needs refreshing related sections + + + + + old rhyme letters to see it needs refreshing related sections + + poem translation @@ -8717,6 +8772,51 @@ review result for rhythm + + + rhythm 2 + + + + + original rhythm 2 + + + + + review result for rhythm 2 + + + + + rhythm 3 + + + + + original rhythm 3 + + + + + review result for rhythm 3 + + + + + rhythm 4 + + + + + original rhythm 4 + + + + + review result for rhythm 4 + + poem summary diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs index a653106d..c4b48d6e 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs @@ -34,6 +34,7 @@ namespace RMuseum.Services.Implementation dbCorrection.ApplicationOrder = await _context.GanjoorPoemCorrections.Where(c => c.Reviewed).AnyAsync() ? 1 + await _context.GanjoorPoemCorrections.Where(c => c.Reviewed).MaxAsync(c => c.ApplicationOrder) : 1; dbCorrection.Reviewed = true; dbCorrection.AffectedThePoem = false; + dbCorrection.ReviewNote = moderation.ReviewNote; if (dbCorrection == null) return new RServiceResult(null); @@ -47,7 +48,7 @@ namespace RMuseum.Services.Implementation if (moderation.Result == CorrectionReviewResult.NotReviewed) return new RServiceResult(null, "تغییرات عنوان بررسی نشده است."); dbCorrection.Result = moderation.Result; - dbCorrection.ReviewNote = moderation.ReviewNote; + if (dbCorrection.Result == CorrectionReviewResult.Approved) { dbCorrection.AffectedThePoem = true; @@ -57,36 +58,89 @@ namespace RMuseum.Services.Implementation } var sections = await _context.GanjoorPoemSections.Where(s => s.PoemId == moderation.PoemId).OrderBy(s => s.SectionType).ThenBy(s => s.Index).ToListAsync(); - - - bool metreChanged = false; + var mainSection = sections.First(s => s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.First); + if (mainSection == null) + { + return new RServiceResult(null, "شعر فاقد بخش اصلی برای ذخیرهٔ وزن است."); + } if (dbCorrection.Rhythm != null) { if (moderation.RhythmResult == CorrectionReviewResult.NotReviewed) return new RServiceResult(null, "تغییرات وزن بررسی نشده است."); dbCorrection.RhythmResult = moderation.RhythmResult; - dbCorrection.ReviewNote = moderation.ReviewNote; if (dbCorrection.RhythmResult == CorrectionReviewResult.Approved) { dbCorrection.AffectedThePoem = true; - var mainSection = sections.First(s => s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.First); - if (mainSection == null) + mainSection.OldGanjoorMetreId = mainSection.GanjoorMetreId; + if (moderation.Rhythm == "") { - return new RServiceResult(null, "شعر فاقد بخش اصلی برای ذخیرهٔ وزن است."); + mainSection.GanjoorMetreId = null; } - var metre = await _context.GanjoorMetres.AsNoTracking().Where(m => m.Rhythm == moderation.Rhythm).SingleOrDefaultAsync(); - if (metre == null) + else { - metre = new GanjoorMetre() + var metre = await _context.GanjoorMetres.AsNoTracking().Where(m => m.Rhythm == moderation.Rhythm).SingleOrDefaultAsync(); + if (metre == null) { - Rhythm = moderation.Rhythm, - VerseCount = 0 - }; - _context.GanjoorMetres.Add(metre); - await _context.SaveChangesAsync(); + metre = new GanjoorMetre() + { + Rhythm = moderation.Rhythm, + VerseCount = 0 + }; + _context.GanjoorMetres.Add(metre); + await _context.SaveChangesAsync(); + } + mainSection.GanjoorMetreId = metre.Id; + } + } + } + + if (dbCorrection.Rhythm2 != null) + { + if (moderation.Rhythm2Result == CorrectionReviewResult.NotReviewed) + return new RServiceResult(null, "تغییرات وزن دوم بررسی نشده است."); + dbCorrection.Rhythm2Result = moderation.RhythmResult; + if (dbCorrection.Rhythm2Result == CorrectionReviewResult.Approved) + { + dbCorrection.AffectedThePoem = true; + var secondMetreSection = sections.First(s => s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.Second); + if (secondMetreSection == null) + { + secondMetreSection = new GanjoorPoemSection() + { + PoemId = dbPoem.Id, + PoetId = mainSection.PoetId, + SectionType = PoemSectionType.WholePoem, + VerseType = VersePoemSectionType.Second, + Index = sections.Max(s => s.Index) + 1, + Number = sections.Max(s => s.Index) + 1 + 1, + GanjoorMetreId = null, + RhymeLetters = mainSection.RhymeLetters, + HtmlText = mainSection.HtmlText, + PlainText = mainSection.PlainText, + PoemFormat = mainSection.PoemFormat, + }; + _context.Add(secondMetreSection); + } + secondMetreSection.OldGanjoorMetreId = secondMetreSection.GanjoorMetreId; + if (moderation.Rhythm == "") + { + secondMetreSection.GanjoorMetreId = null; + } + else + { + var metre = await _context.GanjoorMetres.AsNoTracking().Where(m => m.Rhythm == moderation.Rhythm).SingleOrDefaultAsync(); + if (metre == null) + { + metre = new GanjoorMetre() + { + Rhythm = moderation.Rhythm, + VerseCount = 0 + }; + _context.GanjoorMetres.Add(metre); + await _context.SaveChangesAsync(); + } + secondMetreSection.GanjoorMetreId = metre.Id; } - metreChanged = mainSection.GanjoorMetreId != metre.Id; - mainSection.GanjoorMetreId = metre.Id; } } @@ -128,7 +182,7 @@ namespace RMuseum.Services.Implementation await _context.SaveChangesAsync(); - if (metreChanged || modifiedVerses.Count > 0) + if (modifiedVerses.Count > 0) { foreach (var section in sections) {