diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index ce5719fa..e9b44c65 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -2814,6 +2814,27 @@ namespace RMuseum.Controllers
return Ok();
}
+ ///
+ /// regenerate category related sections
+ ///
+ /// category id
+ ///
+
+ [HttpPut]
+ [Route("cat/{id}/regenrelatedsections")]
+ [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
+ public IActionResult StartRegeneratingCateoryRelatedSections(int id)
+ {
+
+ RServiceResult res =
+ _ganjoorService.StartRegeneratingCateoryRelatedSections(id);
+ if (!string.IsNullOrEmpty(res.ExceptionString))
+ return BadRequest(res.ExceptionString);
+ return Ok(res.Result);
+ }
+
///
/// get a specific poem section
///
@@ -3098,6 +3119,8 @@ namespace RMuseum.Controllers
return Ok(res.Result.Items);
}
+
+
///
/// readonly mode
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 967590f9..258f3761 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -1715,6 +1715,13 @@
+
+
+ regenerate category related sections
+
+ category id
+
+
get a specific poem section
@@ -12699,6 +12706,13 @@
+
+
+ regenerate category related sections
+
+
+
+
translation service implementation
@@ -14459,6 +14473,13 @@
if sent 0 or less returns all items
+
+
+ regenerate category related sections
+
+
+
+
update related sections info (after metreId or rhyme for one of these sections changes)
diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs
index 52c390d4..7136d261 100644
--- a/RMuseum/Services/IGanjoorService.cs
+++ b/RMuseum/Services/IGanjoorService.cs
@@ -1023,5 +1023,13 @@ namespace RMuseum.Services
///
///
Task> GetSectionEffectiveCorrections(int sectionId, PagingParameterModel paging);
+
+
+ ///
+ /// regenerate category related sections
+ ///
+ ///
+ ///
+ RServiceResult StartRegeneratingCateoryRelatedSections(int catId);
}
}
diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-BreakPoem.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-BreakPoem.cs
index fa366897..6cd346a2 100644
--- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-BreakPoem.cs
+++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-BreakPoem.cs
@@ -376,15 +376,7 @@ namespace RMuseum.Services.Implementation
await context.SaveChangesAsync();
- var updatePoemListId = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == dbMainPoem.CatId && p.Id >= dbMainPoem.Id).Select(p => p.Id).ToListAsync();
- foreach (var updatePoemId in updatePoemListId)
- {
- var sections = await context.GanjoorPoemSections.AsNoTracking().Where(s => s.PoemId == updatePoemId && s.GanjoorMetreId != null && !string.IsNullOrEmpty(s.RhymeLetters)).ToListAsync();
- foreach (var section in sections)
- {
- await _UpdateRelatedSections(context, (int)section.GanjoorMetreId, section.RhymeLetters);
- }
- }
+
return new RServiceResult(targetPoemId);
diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs
index 40e1063f..d0b9a4cf 100644
--- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs
+++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs
@@ -40,6 +40,51 @@ namespace RMuseum.Services.Implementation
);
}
+ ///
+ /// regenerate category related sections
+ ///
+ ///
+ ///
+ public RServiceResult StartRegeneratingCateoryRelatedSections(int catId)
+ {
+ try
+ {
+ _backgroundTaskQueue.QueueBackgroundWorkItem
+ (
+ async token =>
+ {
+ using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions())) //this is long running job, so _context might be already been freed/collected by GC
+ {
+ LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
+ var job = (await jobProgressServiceEF.NewJob("StartRegeneratingCateoryRelatedSections", "Query data")).Result;
+ try
+ {
+ var updatePoemListId = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == catId).Select(p => p.Id).ToListAsync();
+ foreach (var updatePoemId in updatePoemListId)
+ {
+ var sections = await context.GanjoorPoemSections.AsNoTracking().Where(s => s.PoemId == updatePoemId && s.GanjoorMetreId != null && !string.IsNullOrEmpty(s.RhymeLetters)).ToListAsync();
+ foreach (var section in sections)
+ {
+ await _UpdateRelatedSections(context, (int)section.GanjoorMetreId, section.RhymeLetters);
+ }
+ }
+ await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
+ }
+ catch (Exception exp)
+ {
+ await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
+ }
+
+ }
+ });
+ return new RServiceResult(true);
+ }
+ catch (Exception exp)
+ {
+ return new RServiceResult(false, exp.ToString());
+ }
+ }
+
///