diff --git a/RMuseum/Controllers/ArtifactController.cs b/RMuseum/Controllers/ArtifactController.cs index 50aef70d..5ec46e3f 100644 --- a/RMuseum/Controllers/ArtifactController.cs +++ b/RMuseum/Controllers/ArtifactController.cs @@ -2008,15 +2008,16 @@ namespace RMuseum.Controllers /// remove ganjoor link /// /// + /// /// [HttpDelete] [Route("ganjoor")] [Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] - public async Task RemoveGanjoorLinkAsync(Guid linkId) + public async Task RemoveGanjoorLinkAsync(Guid linkId, bool removeItemLink) { - RServiceResult suggestion = await _artifactService.RemoveGanjoorLinkAsync(linkId); + RServiceResult suggestion = await _artifactService.RemoveGanjoorLinkAsync(linkId, removeItemLink); if (!string.IsNullOrEmpty(suggestion.ExceptionString)) return BadRequest(suggestion.ExceptionString); return Ok(); diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 8a4c86c0..7c715852 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -585,11 +585,12 @@ display ogn page - + remove ganjoor link + @@ -15285,11 +15286,12 @@ - + remove ganjoor link + @@ -18096,11 +18098,12 @@ - + remove ganjoor link + diff --git a/RMuseum/Services/IArtifactService.cs b/RMuseum/Services/IArtifactService.cs index 2061e905..ed1418f0 100644 --- a/RMuseum/Services/IArtifactService.cs +++ b/RMuseum/Services/IArtifactService.cs @@ -496,8 +496,9 @@ namespace RMuseum.Services /// remove ganjoor link /// /// + /// /// - Task> RemoveGanjoorLinkAsync(Guid id); + Task> RemoveGanjoorLinkAsync(Guid id, bool removeItemLink); /// /// Temporary api diff --git a/RMuseum/Services/Implementation/ArtifactService.cs b/RMuseum/Services/Implementation/ArtifactService.cs index 9b19d443..8518defb 100644 --- a/RMuseum/Services/Implementation/ArtifactService.cs +++ b/RMuseum/Services/Implementation/ArtifactService.cs @@ -3083,8 +3083,9 @@ namespace RMuseum.Services.Implementation /// remove ganjoor link /// /// + /// /// - public async Task> RemoveGanjoorLinkAsync(Guid id) + public async Task> RemoveGanjoorLinkAsync(Guid id, bool removeItemLink) { try { @@ -3092,34 +3093,37 @@ 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) + if(removeItemLink) { - 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}")) + GanjoorPoem poem = await _context.GanjoorPoems.AsNoTracking().Where(p => p.Id == link.GanjoorPostId).SingleOrDefaultAsync(); + if (poem != null) { - var tags = item.Tags.Where(t => t.RTagId == ganjoorlinkTagType.Id && t.ValueSupplement == $"https://ganjoor.net{poem.FullUrl}").ToList(); - foreach (var tag in tags) + 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}")) { - item.Tags.Remove(tag); + 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; } - 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) + 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)) { - item.Tags.Remove(tag); + 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); } - itemNeedsUpdate = true; - } - if (itemNeedsUpdate) - { - _context.Update(item); } } _context.Remove(link); @@ -3532,39 +3536,6 @@ namespace RMuseum.Services.Implementation .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(true);