From ce05b9be0edaaa58bcbd418e4a9b52565e67fbb8 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 25 Sep 2026 15:38:22 +0330 Subject: [PATCH] #421 geo tag suggestion --- GanjooRazor/Areas/User/Pages/Edits.cshtml.cs | 42 +++++++++++++++++++ .../Pages/PoemCorrectionsHistory.cshtml.cs | 42 +++++++++++++++++++ .../GanjoorService-ModeratePoemCorrection.cs | 19 ++++++++- 3 files changed, 102 insertions(+), 1 deletion(-) diff --git a/GanjooRazor/Areas/User/Pages/Edits.cshtml.cs b/GanjooRazor/Areas/User/Pages/Edits.cshtml.cs index 41121246..3cce5365 100644 --- a/GanjooRazor/Areas/User/Pages/Edits.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/Edits.cshtml.cs @@ -283,6 +283,48 @@ namespace GanjooRazor.Areas.User.Pages correction.PoemSummary = currentCorrection.SummaryReviewResult == CorrectionReviewResult.Approved && currentCorrection.PoemSummary != null ? currentCorrection.OriginalPoemSummary ?? "" : null; correction.OriginalPoemSummary = currentCorrection.SummaryReviewResult == CorrectionReviewResult.Approved && currentCorrection.PoemSummary != null ? currentCorrection.PoemSummary : null; + if (currentCorrection.GeoDateTags != null) + { + var geoDateTagsRollback = new List(); + foreach (var geoTag in currentCorrection.GeoDateTags.Where(g => g.Result == CorrectionReviewResult.Approved)) + { + if (geoTag.MarkForDelete) + { + // the original request deleted an existing tag - undo that by re-adding a tag with + // the same data, which was snapshotted onto this same record when it was approved + // (LocationId/LunarYear/etc. are otherwise unused for a pure delete-request) + geoDateTagsRollback.Add(new GanjoorPoemGeoDateTagCorrection() + { + CoupletIndex = geoTag.CoupletIndex, + MarkForDelete = false, + LocationId = geoTag.LocationId, + LunarYear = geoTag.LunarYear, + LunarMonth = geoTag.LunarMonth, + LunarDay = geoTag.LunarDay, + PersonId = geoTag.PersonId, + IgnoreInCategory = geoTag.IgnoreInCategory, + SuggestionNote = $"برگشت حذف برچسب جغرافیایی/تاریخی با کد {correctionId}" + }); + } + else if (geoTag.ExistingTagId != null) + { + // the original request added a new tag - undo that by requesting deletion of the + // live tag it produced (its id was recorded onto ExistingTagId when approved) + geoDateTagsRollback.Add(new GanjoorPoemGeoDateTagCorrection() + { + CoupletIndex = geoTag.CoupletIndex, + MarkForDelete = true, + ExistingTagId = geoTag.ExistingTagId, + SuggestionNote = $"برگشت افزودن برچسب جغرافیایی/تاریخی با کد {correctionId}" + }); + } + } + if (geoDateTagsRollback.Count > 0) + { + correction.GeoDateTags = geoDateTagsRollback.ToArray(); + } + } + correction.Note = $"برگشت تصحیح با کد {correctionId}"; if(!string.IsNullOrEmpty(currentCorrection.Note)) { diff --git a/GanjooRazor/Areas/User/Pages/PoemCorrectionsHistory.cshtml.cs b/GanjooRazor/Areas/User/Pages/PoemCorrectionsHistory.cshtml.cs index ae8a4021..8f9aa482 100644 --- a/GanjooRazor/Areas/User/Pages/PoemCorrectionsHistory.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/PoemCorrectionsHistory.cshtml.cs @@ -243,6 +243,48 @@ namespace GanjooRazor.Areas.User.Pages correction.PoemSummary = currentCorrection.SummaryReviewResult == CorrectionReviewResult.Approved && currentCorrection.PoemSummary != null ? currentCorrection.OriginalPoemSummary ?? "" : null; correction.OriginalPoemSummary = currentCorrection.SummaryReviewResult == CorrectionReviewResult.Approved && currentCorrection.PoemSummary != null ? currentCorrection.PoemSummary : null; + if (currentCorrection.GeoDateTags != null) + { + var geoDateTagsRollback = new List(); + foreach (var geoTag in currentCorrection.GeoDateTags.Where(g => g.Result == CorrectionReviewResult.Approved)) + { + if (geoTag.MarkForDelete) + { + // the original request deleted an existing tag - undo that by re-adding a tag with + // the same data, which was snapshotted onto this same record when it was approved + // (LocationId/LunarYear/etc. are otherwise unused for a pure delete-request) + geoDateTagsRollback.Add(new GanjoorPoemGeoDateTagCorrection() + { + CoupletIndex = geoTag.CoupletIndex, + MarkForDelete = false, + LocationId = geoTag.LocationId, + LunarYear = geoTag.LunarYear, + LunarMonth = geoTag.LunarMonth, + LunarDay = geoTag.LunarDay, + PersonId = geoTag.PersonId, + IgnoreInCategory = geoTag.IgnoreInCategory, + SuggestionNote = $"برگشت حذف برچسب جغرافیایی/تاریخی با کد {correctionId}" + }); + } + else if (geoTag.ExistingTagId != null) + { + // the original request added a new tag - undo that by requesting deletion of the + // live tag it produced (its id was recorded onto ExistingTagId when approved) + geoDateTagsRollback.Add(new GanjoorPoemGeoDateTagCorrection() + { + CoupletIndex = geoTag.CoupletIndex, + MarkForDelete = true, + ExistingTagId = geoTag.ExistingTagId, + SuggestionNote = $"برگشت افزودن برچسب جغرافیایی/تاریخی با کد {correctionId}" + }); + } + } + if (geoDateTagsRollback.Count > 0) + { + correction.GeoDateTags = geoDateTagsRollback.ToArray(); + } + } + correction.Note = $"برگشت تصحیح با کد {correctionId}"; if (!string.IsNullOrEmpty(currentCorrection.Note)) { diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs index a753c85a..cb00cd07 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-ModeratePoemCorrection.cs @@ -680,12 +680,23 @@ namespace RMuseum.Services.Implementation if (dbGeoDateTag.MarkForDelete) { - // approving a delete-suggestion removes the existing, already-approved tag it targets + // approving a delete-suggestion removes the existing, already-approved tag it targets. + // before removing it, snapshot its data onto this correction row itself (reusing the + // already-existing LocationId/LunarYear/etc. columns, which are otherwise unused for a + // pure delete-request) - this is what lets a later "undo this correction" roll the + // deletion back, since the live PoemGeoDateTag row won't exist to read from any more if (dbGeoDateTag.ExistingTagId != null) { var existingTag = await _context.PoemGeoDateTags.Where(t => t.Id == dbGeoDateTag.ExistingTagId).SingleOrDefaultAsync(); if (existingTag != null) { + dbGeoDateTag.LocationId = existingTag.LocationId; + dbGeoDateTag.LunarYear = existingTag.LunarYear; + dbGeoDateTag.LunarMonth = existingTag.LunarMonth; + dbGeoDateTag.LunarDay = existingTag.LunarDay; + dbGeoDateTag.PersonId = existingTag.PersonId; + dbGeoDateTag.IgnoreInCategory = existingTag.IgnoreInCategory; + _context.PoemGeoDateTags.Remove(existingTag); } } @@ -724,6 +735,12 @@ namespace RMuseum.Services.Implementation }; newTag.LunarDateTotalNumber = _PrepareLunarDateTotalNumber(newTag); _context.PoemGeoDateTags.Add(newTag); + await _context.SaveChangesAsync(); // need its Id below + + // record which live tag this correction produced - repurposing ExistingTagId (normally + // only meaningful for a delete-request) so that "undo this correction" can later find + // and remove this exact tag, the same way it removes a newly-added verse or a title change + dbGeoDateTag.ExistingTagId = newTag.Id; } } }