diff --git a/RMuseum/Controllers/ArtifactController.cs b/RMuseum/Controllers/ArtifactController.cs index 98afe250..2c90d8a6 100644 --- a/RMuseum/Controllers/ArtifactController.cs +++ b/RMuseum/Controllers/ArtifactController.cs @@ -243,9 +243,9 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - public async Task RemoveArtifactHavingNoNoteAndBookmarks(Guid artifactId) + public async Task RemoveArtifact(Guid artifactId) { - RServiceResult res = await _artifactService.RemoveArtifactHavingNoNoteAndBookmarks(artifactId, true); + RServiceResult res = await _artifactService.RemoveArtifact(artifactId, true); if (!string.IsNullOrEmpty(res.ExceptionString)) { return BadRequest(res.ExceptionString); diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index b423e830..d7297a00 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -50,7 +50,7 @@ - + remove unpublished artifact having no notes and not bookmarked @@ -8906,7 +8906,7 @@ - + an incomplete prototype for removing artifacts @@ -10281,7 +10281,7 @@ - + an incomplete prototype for removing artifacts diff --git a/RMuseum/Services/IArtifactService.cs b/RMuseum/Services/IArtifactService.cs index 366ada00..6802d4f8 100644 --- a/RMuseum/Services/IArtifactService.cs +++ b/RMuseum/Services/IArtifactService.cs @@ -518,7 +518,7 @@ namespace RMuseum.Services /// /// /// - Task> RemoveArtifactHavingNoNoteAndBookmarks(Guid artifactId, bool checkJobs); + Task> RemoveArtifact(Guid artifactId, bool checkJobs); /// /// start filling GanjoorLink table OriginalSource values diff --git a/RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ImportLoc.cs b/RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ImportLoc.cs index 555ef1f1..0d3f4bbc 100644 --- a/RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ImportLoc.cs +++ b/RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ImportLoc.cs @@ -598,7 +598,7 @@ namespace RMuseum.Services.Implementation scheduled = new List(); foreach (ImportJob job in rescheduledJobs) { - await RemoveArtifactHavingNoNoteAndBookmarks((Guid)job.ArtifactId, false); + await RemoveArtifact((Guid)job.ArtifactId, false); _context.ImportJobs.Remove(job); await _context.SaveChangesAsync(); RServiceResult rescheduled = await StartImportingFromTheLibraryOfCongress(job.ResourceNumber, job.FriendlyUrl, "rbc0001");//plmp diff --git a/RMuseum/Services/Implementation/ArtifactService.cs b/RMuseum/Services/Implementation/ArtifactService.cs index 59683951..f2dd8125 100644 --- a/RMuseum/Services/Implementation/ArtifactService.cs +++ b/RMuseum/Services/Implementation/ArtifactService.cs @@ -1224,15 +1224,10 @@ namespace RMuseum.Services.Implementation /// /// /// - public async Task> RemoveArtifactHavingNoNoteAndBookmarks(Guid artifactId, bool checkJobs) + public async Task> RemoveArtifact(Guid artifactId, bool checkJobs) { try { - if (await _context.UserBookmarks.Where(b => b.RArtifactMasterRecordId == artifactId).AnyAsync()) - return new RServiceResult(false, "The artifcat is bookmarked by somebody and cannot be deleted"); - if (await _context.UserNotes.Where(n => n.RArtifactMasterRecordId == artifactId).AnyAsync()) - return new RServiceResult(false, "The artifcat has notes by somebody and cannot be deleted"); - RArtifactMasterRecord record = await _context.Artifacts .Include(a => a.Items).ThenInclude(i => i.Images) .Include(a => a.Items).ThenInclude(i => i.Tags) @@ -1248,7 +1243,16 @@ namespace RMuseum.Services.Implementation return new RServiceResult(false, "Can not delete published artifact"); } - + if (await _context.UserBookmarks.Where(b => b.RArtifactMasterRecordId == artifactId).AnyAsync()) + { + var bookmarks = await _context.UserBookmarks.Where(b => b.RArtifactMasterRecordId == artifactId).ToListAsync(); + _context.RemoveRange(bookmarks); + } + if (await _context.UserNotes.Where(n => n.RArtifactMasterRecordId == artifactId).AnyAsync()) + { + var notes = await _context.UserNotes.Where(n => n.RArtifactMasterRecordId == artifactId).ToListAsync(); + _context.RemoveRange(notes); + } if (checkJobs) {