#418 regenerate related pages
This commit is contained in:
parent
f7add03083
commit
975aae85e6
@ -3749,8 +3749,9 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> InsertGanjoorQuotedPoemAsync([FromBody] GanjoorQuotedPoem quoted)
|
||||
{
|
||||
var loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<GanjoorQuotedPoem> res =
|
||||
await _ganjoorService.InsertGanjoorQuotedPoemAsync(quoted);
|
||||
await _ganjoorService.InsertGanjoorQuotedPoemAsync(quoted, loggedOnUserId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok(res.Result);
|
||||
@ -3768,8 +3769,9 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> UpdateGanjoorQuotedPoemsAsync([FromBody] GanjoorQuotedPoem quoted)
|
||||
{
|
||||
var loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<bool> res =
|
||||
await _ganjoorService.UpdateGanjoorQuotedPoemsAsync(quoted);
|
||||
await _ganjoorService.UpdateGanjoorQuotedPoemsAsync(quoted, loggedOnUserId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
@ -3787,8 +3789,9 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> DeleteGanjoorQuotedPoemByIdAsync(Guid id)
|
||||
{
|
||||
var loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<bool> res =
|
||||
await _ganjoorService.DeleteGanjoorQuotedPoemByIdAsync(id);
|
||||
await _ganjoorService.DeleteGanjoorQuotedPoemByIdAsync(id, loggedOnUserId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
|
||||
@ -15559,25 +15559,28 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.InsertGanjoorQuotedPoemAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem)">
|
||||
<member name="M:RMuseum.Services.IGanjoorService.InsertGanjoorQuotedPoemAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem,System.Guid)">
|
||||
<summary>
|
||||
insert quoted poem
|
||||
</summary>
|
||||
<param name="quoted"></param>
|
||||
<param name="editingUserId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.UpdateGanjoorQuotedPoemsAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem)">
|
||||
<member name="M:RMuseum.Services.IGanjoorService.UpdateGanjoorQuotedPoemsAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem,System.Guid)">
|
||||
<summary>
|
||||
update quoted poem
|
||||
</summary>
|
||||
<param name="quoted"></param>
|
||||
<param name="editingUserId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteGanjoorQuotedPoemByIdAsync(System.Guid)">
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteGanjoorQuotedPoemByIdAsync(System.Guid,System.Guid)">
|
||||
<summary>
|
||||
delete quoted by id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="editingUserId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IGanjoorTranslationService">
|
||||
@ -17573,25 +17576,28 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.InsertGanjoorQuotedPoemAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.InsertGanjoorQuotedPoemAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem,System.Guid)">
|
||||
<summary>
|
||||
insert quoted poem
|
||||
</summary>
|
||||
<param name="quoted"></param>
|
||||
<param name="editingUserId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.UpdateGanjoorQuotedPoemsAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.UpdateGanjoorQuotedPoemsAsync(RMuseum.Models.Ganjoor.GanjoorQuotedPoem,System.Guid)">
|
||||
<summary>
|
||||
update quoted poem
|
||||
</summary>
|
||||
<param name="quoted"></param>
|
||||
<param name="editingUserId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteGanjoorQuotedPoemByIdAsync(System.Guid)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteGanjoorQuotedPoemByIdAsync(System.Guid,System.Guid)">
|
||||
<summary>
|
||||
delete quoted by id
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="editingUserId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetGanjoorQuotedPoemsAsync(System.Nullable{System.Int32},System.Nullable{System.Int32},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean})">
|
||||
|
||||
@ -1259,21 +1259,24 @@ namespace RMuseum.Services
|
||||
/// insert quoted poem
|
||||
/// </summary>
|
||||
/// <param name="quoted"></param>
|
||||
/// <param name="editingUserId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorQuotedPoem>> InsertGanjoorQuotedPoemAsync(GanjoorQuotedPoem quoted);
|
||||
Task<RServiceResult<GanjoorQuotedPoem>> InsertGanjoorQuotedPoemAsync(GanjoorQuotedPoem quoted, Guid editingUserId);
|
||||
|
||||
/// <summary>
|
||||
/// update quoted poem
|
||||
/// </summary>
|
||||
/// <param name="quoted"></param>
|
||||
/// <param name="editingUserId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> UpdateGanjoorQuotedPoemsAsync(GanjoorQuotedPoem quoted);
|
||||
Task<RServiceResult<bool>> UpdateGanjoorQuotedPoemsAsync(GanjoorQuotedPoem quoted, Guid editingUserId);
|
||||
|
||||
/// <summary>
|
||||
/// delete quoted by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="editingUserId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteGanjoorQuotedPoemByIdAsync(Guid id);
|
||||
Task<RServiceResult<bool>> DeleteGanjoorQuotedPoemByIdAsync(Guid id, Guid editingUserId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -18,6 +17,40 @@ namespace RMuseum.Services.Implementation
|
||||
/// </summary>
|
||||
public partial class GanjoorService : IGanjoorService
|
||||
{
|
||||
public RServiceResult<bool> StartRegeneratingRelatedPoemsPageAsync(Guid editingUserId, int poetId, int relatedPoetId)
|
||||
{
|
||||
try
|
||||
{
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //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($"StartRegeneratingRelatedPoemsPageAsync({poetId}, {relatedPoetId})", "Query data")).Result;
|
||||
|
||||
try
|
||||
{
|
||||
await _RegenerateRelatedPoemsPageAsync(editingUserId, context, poetId, relatedPoetId);
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// parse related pages
|
||||
/// </summary>
|
||||
@ -92,6 +125,11 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
html += $"</p>{Environment.NewLine}";
|
||||
|
||||
if(!string.IsNullOrEmpty(quotedPoem.Note))
|
||||
{
|
||||
html += $"<div class=\"notice\">{quotedPoem.Note}</div>{Environment.NewLine}";
|
||||
}
|
||||
|
||||
html += $"</li>{Environment.NewLine}";
|
||||
}
|
||||
html += $"</ol>{Environment.NewLine}";
|
||||
@ -154,6 +192,11 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
html += $"</p>{Environment.NewLine}";
|
||||
|
||||
if (!string.IsNullOrEmpty(quotedPoem.Note))
|
||||
{
|
||||
html += $"<div class=\"notice\">{quotedPoem.Note}</div>{Environment.NewLine}";
|
||||
}
|
||||
|
||||
html += $"</li>{Environment.NewLine}";
|
||||
}
|
||||
html += $"</ol>{Environment.NewLine}";
|
||||
@ -264,8 +307,9 @@ namespace RMuseum.Services.Implementation
|
||||
/// insert quoted poem
|
||||
/// </summary>
|
||||
/// <param name="quoted"></param>
|
||||
/// <param name="editingUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<GanjoorQuotedPoem>> InsertGanjoorQuotedPoemAsync(GanjoorQuotedPoem quoted)
|
||||
public async Task<RServiceResult<GanjoorQuotedPoem>> InsertGanjoorQuotedPoemAsync(GanjoorQuotedPoem quoted, Guid editingUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -291,7 +335,14 @@ namespace RMuseum.Services.Implementation
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
if (quoted.RelatedPoetId != null)
|
||||
{
|
||||
var page = await _context.GanjoorPages.AsNoTracking().Where(p => p.PoetId == quoted.PoetId && p.SecondPoetId == quoted.RelatedPoetId).SingleOrDefaultAsync();
|
||||
if(page != null)
|
||||
{
|
||||
StartRegeneratingRelatedPoemsPageAsync(editingUserId, quoted.PoetId, (int)quoted.RelatedPoetId);
|
||||
}
|
||||
}
|
||||
|
||||
return new RServiceResult<GanjoorQuotedPoem>(quoted);
|
||||
|
||||
@ -306,8 +357,9 @@ namespace RMuseum.Services.Implementation
|
||||
/// update quoted poem
|
||||
/// </summary>
|
||||
/// <param name="quoted"></param>
|
||||
/// <param name="editingUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> UpdateGanjoorQuotedPoemsAsync(GanjoorQuotedPoem quoted)
|
||||
public async Task<RServiceResult<bool>> UpdateGanjoorQuotedPoemsAsync(GanjoorQuotedPoem quoted, Guid editingUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -357,6 +409,15 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (quoted.RelatedPoetId != null)
|
||||
{
|
||||
var page = await _context.GanjoorPages.AsNoTracking().Where(p => p.PoetId == quoted.PoetId && p.SecondPoetId == quoted.RelatedPoetId).SingleOrDefaultAsync();
|
||||
if (page != null)
|
||||
{
|
||||
StartRegeneratingRelatedPoemsPageAsync(editingUserId, quoted.PoetId, (int)quoted.RelatedPoetId);
|
||||
}
|
||||
}
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
|
||||
}
|
||||
@ -370,13 +431,16 @@ namespace RMuseum.Services.Implementation
|
||||
/// delete quoted by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="editingUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> DeleteGanjoorQuotedPoemByIdAsync(Guid id)
|
||||
public async Task<RServiceResult<bool>> DeleteGanjoorQuotedPoemByIdAsync(Guid id, Guid editingUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var q = await _context.GanjoorQuotedPoems.Where(q => q.Id == id).SingleAsync();
|
||||
var poemId = q.PoemId;
|
||||
var poetId = q.PoetId;
|
||||
var relatedPoetId = q.RelatedPoetId;
|
||||
var relatedPoemId = q.RelatedPoemId;
|
||||
_context.Remove(q);
|
||||
await _context.SaveChangesAsync();
|
||||
@ -398,6 +462,15 @@ namespace RMuseum.Services.Implementation
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
if (relatedPoetId != null)
|
||||
{
|
||||
var page = await _context.GanjoorPages.AsNoTracking().Where(p => p.PoetId == poetId && p.SecondPoetId == relatedPoetId).SingleOrDefaultAsync();
|
||||
if (page != null)
|
||||
{
|
||||
StartRegeneratingRelatedPoemsPageAsync(editingUserId, poetId, (int)relatedPoetId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user