Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files, folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*). External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed consistently (no pending model changes); requires a fresh database. Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using RSecurityBackend.Models.Generic;
|
|
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RMuseum.Services.Implementation
|
|
{
|
|
/// <summary>
|
|
/// IDivanService implementation
|
|
/// </summary>
|
|
public partial class DivanService : IDivanService
|
|
{
|
|
|
|
/// <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.DivanMetres.Where(m => m.Id == srcMeterId).SingleAsync();
|
|
var dest = await _context.DivanMetres.Where(m => m.Id == destMeterId).SingleAsync();
|
|
var poems = await _context.DivanPoems.Where(p => p.DivanMetreId == srcMeterId).ToListAsync();
|
|
foreach (var poem in poems)
|
|
{
|
|
poem.DivanMetreId = destMeterId;
|
|
}
|
|
_context.UpdateRange(poems);
|
|
|
|
var sections = await _context.DivanPoemSections.Where(s => s.DivanMetreId == srcMeterId).ToListAsync();
|
|
foreach (var section in sections)
|
|
{
|
|
section.DivanMetreId = 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());
|
|
}
|
|
}
|
|
}
|
|
} |