public async Task <IActionResult> DeletePage(string id) { List <KirjaPage> kirjaPages = await _pageDbAccess.GetPagesByPage(id); if (kirjaPages.Count > 0) { string mentionedInPages = string.Join(", ", kirjaPages.Select(p => p.Name)); return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeletePageMentionedInOtherPages", mentionedInPages].Value)); } List <KartaMapMarkerQueryResult> kartaMaps = await _kartaMapDbAccess.GetAllMapsKirjaPageIsMarkedIn(id); if (kartaMaps.Count > 0) { string markedInMaps = string.Join(", ", kartaMaps.Select(p => p.Name)); return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeletePageMarkedInKartaMap", markedInMaps].Value)); } KirjaPage page = await _pageDbAccess.GetPageById(id); await _pageDbAccess.DeletePage(page); _logger.LogInformation("Page was deleted."); if (page.UplodadedImages != null) { DeleteUnusedImages(page.UplodadedImages); } await _timelineService.AddTimelineEntry(TimelineEvent.KirjaPageDeleted, page.Name); return(Ok(id)); }
public async Task <IActionResult> DeletePage(string id) { List <KirjaPage> kirjaPages = await _pageDbAccess.GetPagesByPage(id); if (kirjaPages.Count > 0) { string mentionedInPages = string.Join(", ", kirjaPages.Select(p => p.Name)); return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeletePageMentionedInOtherPages", mentionedInPages].Value)); } List <KartaMapMarkerQueryResult> kartaMaps = await _kartaMapDbAccess.GetAllMapsKirjaPageIsMarkedIn(id); if (kartaMaps.Count > 0) { string markedInMaps = string.Join(", ", kartaMaps.Select(p => p.Name)); return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeletePageMarkedInKartaMap", markedInMaps].Value)); } KirjaPage page = await _pageDbAccess.GetPageById(id); if (page.IsDefault) { return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeleteRootPage"].Value)); } await _pageDbAccess.DeletePage(page); _logger.LogInformation("Page was deleted."); // Delete Images List <string> allImages = new List <string>(); if (page.UplodadedImages != null) { allImages.AddRange(page.UplodadedImages); } List <KirjaPageVersion> oldVersions = await _pageVersionDbAccess.GetVersionsOfPage(page.Id, 0, int.MaxValue); foreach (KirjaPageVersion curVersion in oldVersions) { if (curVersion.UplodadedImages != null) { allImages.AddRange(curVersion.UplodadedImages); } } allImages = allImages.Distinct().ToList(); foreach (string curImage in allImages) { _fileAccess.DeleteFile(curImage); } // Delete Attachments if (page.Attachments != null) { foreach (KirjaPageAttachment curAttachment in page.Attachments) { _fileAccess.DeleteFile(curAttachment.Filename); } } await _pageVersionDbAccess.DeletePageVersionsByPage(page.Id); await _timelineService.AddTimelineEntry(TimelineEvent.KirjaPageDeleted, page.Name); return(Ok(id)); }
public async Task <IActionResult> DeletePage(string id) { List <KirjaPage> kirjaPages = await _pageDbAccess.GetPagesByPage(id); if (kirjaPages.Count > 0) { string mentionedInPages = string.Join(", ", kirjaPages.Select(p => p.Name)); return(BadRequest(_localizer["CanNotDeletePageMentionedInOtherPages", mentionedInPages].Value)); } List <KartaMapMarkerQueryResult> kartaMaps = await _kartaMapDbAccess.GetAllMapsKirjaPageIsMarkedIn(id); if (kartaMaps.Count > 0) { string markedInMaps = string.Join(", ", kartaMaps.Select(p => p.Name)); return(BadRequest(_localizer["CanNotDeletePageMarkedInKartaMap", markedInMaps].Value)); } List <TaleDialog> taleDialogs = await _dialogDbAccess.GetDialogsObjectIsReferenced(id); if (taleDialogs.Count > 0) { List <KortistoNpc> npcs = await _npcDbAccess.ResolveFlexFieldObjectNames(taleDialogs.Select(t => t.RelatedObjectId).ToList()); string referencedInDialogs = string.Join(", ", npcs.Select(n => n.Name)); return(BadRequest(_localizer["CanNotDeletePageReferencedInDialog", referencedInDialogs].Value)); } List <KortistoNpc> usedNpcs = await _npcDbAccess.GetNpcsObjectIsReferencedInDailyRoutine(id); if (usedNpcs.Count > 0) { string referencedInNpcs = string.Join(", ", usedNpcs.Select(p => p.Name)); return(BadRequest(_localizer["CanNotDeletePageReferencedInNpc", referencedInNpcs].Value)); } List <AikaQuest> aikaQuests = await _questDbAccess.GetQuestsObjectIsReferenced(id); if (aikaQuests.Count > 0) { string referencedInQuests = string.Join(", ", aikaQuests.Select(p => p.Name)); return(BadRequest(_localizer["CanNotDeletePageReferencedInQuest", referencedInQuests].Value)); } List <EvneSkill> referencedInSkills = await _skillDbAccess.GetSkillsObjectIsReferencedIn(id); if (referencedInSkills.Count > 0) { string usedInSkills = string.Join(", ", referencedInSkills.Select(m => m.Name)); return(BadRequest(_localizer["CanNotDeletePageReferencedInSkill", usedInSkills].Value)); } List <ObjectExportSnippet> referencedInSnippets = await _objectExportSnippetDbAccess.GetExportSnippetsObjectIsReferenced(id); if (referencedInSnippets.Count > 0) { List <ObjectExportSnippetReference> references = await _exportSnippetRelatedObjectNameResolver.ResolveExportSnippetReferences(referencedInSnippets, true, true, true); string usedInDailyRoutines = string.Join(", ", references.Select(m => string.Format("{0} ({1})", m.ObjectName, m.ExportSnippet))); return(BadRequest(_localizer["CanNotDeletePageReferencedInExportSnippet", usedInDailyRoutines].Value)); } List <StateMachine> referencedInStateMachines = await _stateMachineDbAccess.GetStateMachinesObjectIsReferenced(id); if (referencedInStateMachines.Count > 0) { List <KortistoNpc> npcs = await _npcDbAccess.ResolveFlexFieldObjectNames(referencedInStateMachines.Select(t => t.RelatedObjectId).ToList()); List <KortistoNpc> npcTemplates = await _npcTemplateDbAccess.ResolveFlexFieldObjectNames(referencedInStateMachines.Select(t => t.RelatedObjectId).ToList()); string usedInStateMachines = string.Join(", ", npcs.Union(npcTemplates).Select(n => n.Name)); return(BadRequest(_localizer["CanNotDeletePageUsedInStateMachines", usedInStateMachines].Value)); } KirjaPage page = await _pageDbAccess.GetPageById(id); if (page.IsDefault) { return(BadRequest(_localizer["CanNotDeleteRootPage"].Value)); } await _pageDbAccess.DeletePage(page); _logger.LogInformation("Page was deleted."); // Delete Images List <string> allImages = new List <string>(); if (page.UplodadedImages != null) { allImages.AddRange(page.UplodadedImages); } List <KirjaPageVersion> oldVersions = await _pageVersionDbAccess.GetVersionsOfPage(page.Id, 0, int.MaxValue); foreach (KirjaPageVersion curVersion in oldVersions) { if (curVersion.UplodadedImages != null) { allImages.AddRange(curVersion.UplodadedImages); } } allImages = allImages.Distinct().ToList(); foreach (string curImage in allImages) { _fileAccess.DeleteFile(curImage); } // Delete Attachments if (page.Attachments != null) { foreach (KirjaPageAttachment curAttachment in page.Attachments) { _fileAccess.DeleteFile(curAttachment.Filename); } } await _pageVersionDbAccess.DeletePageVersionsByPage(page.Id); await _timelineService.AddTimelineEntry(page.ProjectId, TimelineEvent.KirjaPageDeleted, page.Name); return(Ok(id)); }