#458 unlink links

This commit is contained in:
Hamid Reza Mohammadi 2025-01-17 13:46:14 +03:30
parent 8ff63db78e
commit 8d0b3761f4

View File

@ -28,10 +28,7 @@ using System.Threading.Tasks;
using DNTPersianUtils.Core;
using FluentFTP;
using RSecurityBackend.Models.Notification;
using RMuseum.Models.PDFLibrary;
using Microsoft.Identity.Client;
using Org.BouncyCastle.Utilities.Collections;
using static System.Windows.Forms.LinkLabel;
using RMuseum.Models.Ganjoor;
namespace RMuseum.Services.Implementation
{
@ -3068,6 +3065,36 @@ namespace RMuseum.Services.Implementation
await _context.GanjoorLinks
.Where(l => l.Id == id)
.SingleAsync();
GanjoorPoem poem = await _context.GanjoorPoems.AsNoTracking().Where(p => p.Id == link.GanjoorPostId).SingleOrDefaultAsync();
if (poem != null)
{
var item = await _context.Items.Include(i => i.Tags).Where(i => i.Id == link.ItemId).SingleAsync();
bool itemNeedsUpdate = false;
RTag ganjoorlinkTagType = await _context.Tags.AsNoTracking().Where(a => a.NameInEnglish == "Ganjoor Link").SingleAsync();
if (item.Tags.Any(t => t.RTagId == ganjoorlinkTagType.Id && t.ValueSupplement == $"https://ganjoor.net{poem.FullUrl}"))
{
var tags = item.Tags.Where(t => t.RTagId == ganjoorlinkTagType.Id && t.ValueSupplement == $"https://ganjoor.net{poem.FullUrl}").ToList();
foreach (var tag in tags)
{
item.Tags.Remove(tag);
}
itemNeedsUpdate = true;
}
RTag ganjoorTOCTagType = await _context.Tags.AsNoTracking().Where(a => a.NameInEnglish == "Title in TOC").SingleAsync();
if (item.Tags.Any(t => t.RTagId == ganjoorTOCTagType.Id && t.Value == poem.FullTitle))
{
var tags = item.Tags.Where(t => t.RTagId == ganjoorTOCTagType.Id && t.Value == poem.FullTitle).ToList();
foreach (var tag in tags)
{
item.Tags.Remove(tag);
}
itemNeedsUpdate = true;
}
if (itemNeedsUpdate)
{
_context.Update(item);
}
}
_context.Remove(link);
await _context.SaveChangesAsync();
return new RServiceResult<bool>(true);
@ -3477,6 +3504,40 @@ namespace RMuseum.Services.Implementation
await _context.PinterestLinks
.Where(l => l.Id == id)
.SingleAsync();
GanjoorPoem poem = await _context.GanjoorPoems.AsNoTracking().Where(p => p.Id == link.GanjoorPostId).SingleOrDefaultAsync();
if(poem != null)
{
var item = await _context.Items.Include(i => i.Tags).Where(i => i.Id == link.ItemId).SingleAsync();
bool itemNeedsUpdate = false;
RTag ganjoorlinkTagType = await _context.Tags.AsNoTracking().Where(a => a.NameInEnglish == "Ganjoor Link").SingleAsync();
if(item.Tags.Any(t => t.RTagId == ganjoorlinkTagType.Id && t.ValueSupplement == $"https://ganjoor.net{poem.FullUrl}"))
{
var tags = item.Tags.Where(t => t.RTagId == ganjoorlinkTagType.Id && t.ValueSupplement == $"https://ganjoor.net{poem.FullUrl}").ToList();
foreach (var tag in tags)
{
item.Tags.Remove(tag);
}
itemNeedsUpdate = true;
}
RTag ganjoorTOCTagType = await _context.Tags.AsNoTracking().Where(a => a.NameInEnglish == "Title in TOC").SingleAsync();
if (item.Tags.Any(t => t.RTagId == ganjoorTOCTagType.Id && t.Value == poem.FullTitle))
{
var tags = item.Tags.Where(t => t.RTagId == ganjoorTOCTagType.Id && t.Value == poem.FullTitle).ToList();
foreach (var tag in tags)
{
item.Tags.Remove(tag);
}
itemNeedsUpdate = true;
}
if(itemNeedsUpdate)
{
_context.Update(item);
}
}
_context.Remove(link);
await _context.SaveChangesAsync();
return new RServiceResult<bool>(true);