docs: #347 move poems from prosody meters and delete duplicated meters

This commit is contained in:
Hamid Reza Mohammadi 2022-07-14 17:02:32 +04:30
parent 1451886aac
commit 74ffcb4633
4 changed files with 125 additions and 1 deletions

View File

@ -3181,7 +3181,28 @@ namespace RMuseum.Controllers
return Ok(res.Result.Items);
}
/// <summary>
/// transfer poems and sections from a meter to another one and delete the source meter
/// </summary>
/// <param name="srcId"></param>
/// <param name="destId"></param>
/// <returns></returns>
[HttpPut]
[Route("prosody/transfer/{srcId}/{destId}")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> TransferMeterAsync(int srcId, int destId)
{
RServiceResult<bool> res =
await _ganjoorService.TransferMeterAsync(srcId, destId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok();
}
/// <summary>

View File

@ -1820,6 +1820,14 @@
<param name="paging"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.TransferMeterAsync(System.Int32,System.Int32)">
<summary>
transfer poems and sections from a meter to another one and delete the source meter
</summary>
<param name="srcId"></param>
<param name="destId"></param>
<returns></returns>
</member>
<member name="P:RMuseum.Controllers.GanjoorController.ReadOnlyMode">
<summary>
readonly mode
@ -12762,6 +12770,14 @@
<param name="catId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.TransferMeterAsync(System.Int32,System.Int32)">
<summary>
transfer poems and sections from a meter to another one
</summary>
<param name="srcMeterId"></param>
<param name="destMeterId"></param>
<returns></returns>
</member>
<member name="T:RMuseum.Services.IGanjoorTranslationService">
<summary>
translation service implementation
@ -14152,6 +14168,9 @@
<summary>
IGanjoorService implementation
</summary>
<summary>
IGanjoorService implementation
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.SwitchCoupletBookmark(System.Guid,System.Int32,System.Int32)">
<summary>
@ -14324,6 +14343,14 @@
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.TransferMeterAsync(System.Int32,System.Int32)">
<summary>
transfer poems and sections from a meter to another one
</summary>
<param name="srcMeterId"></param>
<param name="destMeterId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.ModeratePoemCorrection(System.Guid,RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemCorrectionViewModel)">
<summary>
moderate poem correction

View File

@ -1044,5 +1044,13 @@ namespace RMuseum.Services
/// <param name="catId"></param>
/// <returns></returns>
RServiceResult<bool> StartRegeneratingCateoryRelatedSections(int catId);
/// <summary>
/// transfer poems and sections from a meter to another one
/// </summary>
/// <param name="srcMeterId"></param>
/// <param name="destMeterId"></param>
/// <returns></returns>
Task<RServiceResult<bool>> TransferMeterAsync(int srcMeterId, int destMeterId);
}
}

View File

@ -0,0 +1,68 @@
using Microsoft.EntityFrameworkCore;
using RSecurityBackend.Models.Generic;
using System;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace RMuseum.Services.Implementation
{
/// <summary>
/// IGanjoorService implementation
/// </summary>
public partial class GanjoorService : IGanjoorService
{
/// <summary>
/// transfer poems and sections from a meter to another one
/// </summary>
/// <param name="srcMeterId"></param>
/// <param name="destMeterId"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> TransferMeterAsync(int srcMeterId, int destMeterId)
{
try
{
if (srcMeterId == destMeterId)
return new RServiceResult<bool>(false, "srcMeterId == destMeterId");
var src = await _context.GanjoorMetres.Where(m => m.Id == srcMeterId).SingleAsync();
var dest = await _context.GanjoorMetres.Where(m => m.Id == destMeterId).SingleAsync();
var poems = await _context.GanjoorPoems.Where(p => p.GanjoorMetreId == srcMeterId).ToListAsync();
foreach (var poem in poems)
{
poem.GanjoorMetreId = destMeterId;
}
_context.UpdateRange(poems);
var sections = await _context.GanjoorPoemSections.Where(s => s.GanjoorMetreId == srcMeterId).ToListAsync();
foreach (var section in sections)
{
section.GanjoorMetreId = destMeterId;
}
_context.UpdateRange(sections);
await _context.SaveChangesAsync();
dest.VerseCount += src.VerseCount;
_context.Update(dest);
await _context.SaveChangesAsync();
_context.Remove(src);
await _context.SaveChangesAsync();
foreach (var section in sections)
{
if (!string.IsNullOrEmpty(section.RhymeLetters))
{
UpdateRelatedSections(destMeterId, section.RhymeLetters);
}
}
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
}
}