public async Task <IActionResult> UpdatePage(string id, [FromBody] PageRequest page) { KirjaPage loadedPage = await _pageDbAccess.GetPageById(id); List <string> oldImages = null; if (loadedPage.UplodadedImages != null) { oldImages = new List <string>(loadedPage.UplodadedImages); } else { oldImages = new List <string>(); } loadedPage.Name = page.Name; loadedPage.Content = page.Content; _pageParserService.ParsePage(loadedPage); await this.SetModifiedData(_userManager, loadedPage); await _pageDbAccess.UpdatePage(loadedPage); _logger.LogInformation("Page was updated."); DeleteUnusedImages(oldImages.Except(loadedPage.UplodadedImages, StringComparer.OrdinalIgnoreCase).ToList()); _logger.LogInformation("Unused Images were deleted."); await _timelineService.AddTimelineEntry(TimelineEvent.KirjaPageUpdated, loadedPage.Name, loadedPage.Id); return(Ok(loadedPage)); }
/// <summary> /// Deletes the modified data for the user /// </summary> /// <param name="user">User</param> /// <returns>Task</returns> private async Task DeleteModifiedData(GoNorthUser user) { List <AikaQuest> quests = await _questDbAccess.GetQuestsByModifiedUser(user.Id); foreach (AikaQuest curQuest in quests) { curQuest.ModifiedBy = Guid.Empty.ToString(); curQuest.ModifiedOn = DateTimeOffset.UtcNow; await _questDbAccess.UpdateQuest(curQuest); } List <AikaChapterDetail> chapterDetail = await _chapterDetailDbAccess.GetChapterDetailsByModifiedUser(user.Id); foreach (AikaChapterDetail curChapterDetail in chapterDetail) { curChapterDetail.ModifiedBy = Guid.Empty.ToString(); curChapterDetail.ModifiedOn = DateTimeOffset.UtcNow; await _chapterDetailDbAccess.UpdateChapterDetail(curChapterDetail); } List <AikaChapterOverview> chapterOverview = await _chapterOverviewDbAccess.GetChapterOverviewByModifiedUser(user.Id); foreach (AikaChapterOverview curOverview in chapterOverview) { curOverview.ModifiedBy = Guid.Empty.ToString(); curOverview.ModifiedOn = DateTimeOffset.UtcNow; await _chapterOverviewDbAccess.UpdateChapterOverview(curOverview); } List <EvneSkill> skills = await _skillDbAccess.GetFlexFieldObjectsByModifiedUser(user.Id); foreach (EvneSkill curSkill in skills) { curSkill.ModifiedBy = Guid.Empty.ToString(); curSkill.ModifiedOn = DateTimeOffset.UtcNow; await _skillDbAccess.UpdateFlexFieldObject(curSkill); } List <KortistoNpc> npcs = await _npcDbAccess.GetFlexFieldObjectsByModifiedUser(user.Id); foreach (KortistoNpc curNpc in npcs) { curNpc.ModifiedBy = Guid.Empty.ToString(); curNpc.ModifiedOn = DateTimeOffset.UtcNow; await _npcDbAccess.UpdateFlexFieldObject(curNpc); } List <StyrItem> items = await _itemDbAccess.GetFlexFieldObjectsByModifiedUser(user.Id); foreach (StyrItem curItem in items) { curItem.ModifiedBy = Guid.Empty.ToString(); curItem.ModifiedOn = DateTimeOffset.UtcNow; await _itemDbAccess.UpdateFlexFieldObject(curItem); } List <ExportTemplate> exportTemplates = await _exportTemplateDbAccess.GetExportTemplatesByModifiedUser(user.Id); foreach (ExportTemplate curTemplate in exportTemplates) { curTemplate.ModifiedBy = Guid.Empty.ToString(); curTemplate.ModifiedOn = DateTimeOffset.UtcNow; await _exportTemplateDbAccess.UpdateTemplate(curTemplate); } List <KartaMap> maps = await _mapDbAccess.GetMapsByModifiedUser(user.Id); foreach (KartaMap curMap in maps) { curMap.ModifiedBy = Guid.Empty.ToString(); curMap.ModifiedOn = DateTimeOffset.UtcNow; await _mapDbAccess.UpdateMap(curMap); } List <KirjaPage> pages = await _pageDbAccess.GetPagesByModifiedUser(user.Id); foreach (KirjaPage curPage in pages) { curPage.ModifiedBy = Guid.Empty.ToString(); curPage.ModifiedOn = DateTimeOffset.UtcNow; await _pageDbAccess.UpdatePage(curPage); } List <KirjaPageVersion> pageVersions = await _pageVersionDbAccess.GetPageVersionsByModifiedUser(user.Id); foreach (KirjaPageVersion curVersion in pageVersions) { curVersion.ModifiedBy = Guid.Empty.ToString(); curVersion.ModifiedOn = DateTimeOffset.UtcNow; await _pageVersionDbAccess.UpdatePageVersion(curVersion); } List <TaleDialog> dialogs = await _taleDbAccess.GetDialogsByModifiedUser(user.Id); foreach (TaleDialog curDialog in dialogs) { curDialog.ModifiedBy = Guid.Empty.ToString(); curDialog.ModifiedOn = DateTimeOffset.UtcNow; await _taleDbAccess.UpdateDialog(curDialog); } List <JsonConfigEntry> jsonConfigEntries = await _projectConfigDbAccess.GetJsonConfigEntriesByModifiedUser(user.Id); foreach (JsonConfigEntry curConfig in jsonConfigEntries) { curConfig.ModifiedBy = Guid.Empty.ToString(); curConfig.ModifiedOn = DateTimeOffset.UtcNow; await _projectConfigDbAccess.UpdateJsonConfig(curConfig); } List <MiscProjectConfig> miscConfigEntries = await _projectConfigDbAccess.GetMiscConfigEntriesByModifiedUser(user.Id); foreach (MiscProjectConfig curMiscConfig in miscConfigEntries) { curMiscConfig.ModifiedBy = Guid.Empty.ToString(); curMiscConfig.ModifiedOn = DateTimeOffset.UtcNow; await _projectConfigDbAccess.UpdateMiscConfig(curMiscConfig); } List <TaskBoard> taskBoards = await _taskBoardDbAccess.GetTaskBoardsByModifiedUser(user.Id); foreach (TaskBoard curBoard in taskBoards) { if (curBoard.ModifiedBy == user.Id) { curBoard.ModifiedBy = Guid.Empty.ToString(); curBoard.ModifiedOn = DateTimeOffset.UtcNow; } List <TaskGroup> modifiedGroups = curBoard.TaskGroups.Where(t => t.ModifiedBy == user.Id).ToList(); foreach (TaskGroup curTaskGroup in modifiedGroups) { curTaskGroup.ModifiedBy = Guid.Empty.ToString(); curTaskGroup.ModifiedOn = DateTimeOffset.UtcNow; } List <GoNorthTask> tasks = curBoard.TaskGroups.SelectMany(p => p.Tasks.Where(t => t.ModifiedBy == user.Id)).ToList(); if (tasks.Count > 0) { foreach (GoNorthTask curTask in tasks) { curTask.ModifiedBy = Guid.Empty.ToString(); curTask.ModifiedOn = DateTimeOffset.UtcNow; } } await _taskBoardDbAccess.UpdateTaskBoard(curBoard); } List <GoNorthTaskType> taskGroupTypes = await _taskGroupTypeDbAccess.GetTaskTypesByModifiedUser(user.Id); foreach (GoNorthTaskType curType in taskGroupTypes) { curType.ModifiedBy = Guid.Empty.ToString(); curType.ModifiedOn = DateTimeOffset.UtcNow; await _taskGroupTypeDbAccess.UpdateTaskType(curType); } List <GoNorthTaskType> taskTypes = await _taskTypeDbAccess.GetTaskTypesByModifiedUser(user.Id); foreach (GoNorthTaskType curType in taskTypes) { curType.ModifiedBy = Guid.Empty.ToString(); curType.ModifiedOn = DateTimeOffset.UtcNow; await _taskTypeDbAccess.UpdateTaskType(curType); } }
public async Task <IActionResult> UpdatePage(string id, [FromBody] PageRequest page) { _xssChecker.CheckXss(page.Name); _xssChecker.CheckXss(page.Content); KirjaPage loadedPage = await _pageDbAccess.GetPageById(id); if (loadedPage == null) { return(NotFound()); } List <string> oldImages = null; if (loadedPage.UplodadedImages != null) { oldImages = new List <string>(loadedPage.UplodadedImages); } else { oldImages = new List <string>(); } bool nameChanged = loadedPage.Name != page.Name; loadedPage.Name = page.Name; loadedPage.Content = page.Content; _pageParserService.ParsePage(loadedPage); await this.SetModifiedData(_userManager, loadedPage); await _pageDbAccess.UpdatePage(loadedPage); _logger.LogInformation("Page was updated."); if (nameChanged) { await SyncPageNameToMarkers(id, page.Name); } string versionId = await SaveVersionOfPage(loadedPage); string oldVersionId = string.Empty; if (!string.IsNullOrEmpty(versionId)) { List <KirjaPageVersion> allVersions = await _pageVersionDbAccess.GetVersionsOfPage(loadedPage.Id, 0, 2); if (allVersions.Count > 1) { oldVersionId = allVersions[1].Id; } } _logger.LogInformation("Versions were updated."); await DeleteUnusedImages(loadedPage.Id, oldImages.Except(loadedPage.UplodadedImages, StringComparer.OrdinalIgnoreCase).ToList()); _logger.LogInformation("Unused Images were deleted."); await _timelineService.AddTimelineEntry(TimelineEvent.KirjaPageUpdated, loadedPage.Name, loadedPage.Id, versionId, oldVersionId); return(Ok(loadedPage)); }