public async Task <IActionResult> FlagMarkerAsImplemented(string mapId, string markerId, MarkerType markerType) { // Check Data KartaMap map = await _mapDbAccess.GetMapById(mapId); if (map == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } // Flag Marker as implemented if (markerType == MarkerType.Npc && map.NpcMarker != null) { NpcMapMarker marker = map.NpcMarker.First(m => m.Id == markerId); marker.IsImplemented = true; await _markerSnapshotDbAccess.SaveNpcMarkerSnapshot(marker); await _mapDbAccess.UpdateMap(map); } else if (markerType == MarkerType.Item && map.ItemMarker != null) { ItemMapMarker marker = map.ItemMarker.First(m => m.Id == markerId); marker.IsImplemented = true; await _markerSnapshotDbAccess.SaveItemMarkerSnapshot(marker); await _mapDbAccess.UpdateMap(map); } else if (markerType == MarkerType.MapChange && map.MapChangeMarker != null) { MapChangeMapMarker marker = map.MapChangeMarker.First(m => m.Id == markerId); marker.IsImplemented = true; await _markerSnapshotDbAccess.SaveMapChangeMarkerSnapshot(marker); await _mapDbAccess.UpdateMap(map); } else if (markerType == MarkerType.Quest && map.MapChangeMarker != null) { QuestMapMarker marker = map.QuestMarker.First(m => m.Id == markerId); marker.IsImplemented = true; await _markerSnapshotDbAccess.SaveQuestMarkerSnapshot(marker); await _mapDbAccess.UpdateMap(map); } else if (markerType == MarkerType.Note && map.NoteMarker != null) { NoteMapMarker marker = map.NoteMarker.First(m => m.Id == markerId); marker.IsImplemented = true; await _markerSnapshotDbAccess.SaveNoteMarkerSnapshot(marker); await _mapDbAccess.UpdateMap(map); } // Add Timeline entry await _timelineService.AddTimelineEntry(TimelineEvent.ImplementedMarker, mapId, markerId, markerType.ToString(), map.Name); return(Ok()); }
/// <summary> /// Syncs the labels of the markers /// </summary> /// <returns>Task</returns> public async Task SyncMarkerLabels() { List <KartaMap> maps = await _kartaMapDbAccess.GetAllMaps(); foreach (KartaMap curMap in maps) { await SyncKirjaMarkerLabels(curMap); await SyncKortistoMarkerLabels(curMap); await SyncStyrMarkerLabels(curMap); await SyncKartaMapChangeMarkerLabels(curMap); await _kartaMapDbAccess.UpdateMap(curMap); } }
/// <summary> /// Syncs the npc name to markers after an update /// </summary> /// <param name="id">Id of the npc</param> /// <param name="npcName">New npc name</param> /// <returns>Task</returns> private async Task SyncNpcNameToMarkers(string id, string npcName) { List <KartaMapMarkerQueryResult> markerResult = await _kartaMapDbAccess.GetAllMapsNpcIsMarkedIn(id); foreach (KartaMapMarkerQueryResult curMapQueryResult in markerResult) { KartaMap map = await _kartaMapDbAccess.GetMapById(curMapQueryResult.MapId); foreach (NpcMapMarker curMarker in map.NpcMarker) { if (curMarker.NpcId == id) { curMarker.NpcName = npcName; } } await _kartaMapDbAccess.UpdateMap(map); } }
/// <summary> /// Syncs the page name to markers after an update /// </summary> /// <param name="id">Id of the page</param> /// <param name="pageName">New page name</param> /// <returns>Task</returns> private async Task SyncPageNameToMarkers(string id, string pageName) { List <KartaMapMarkerQueryResult> markerResult = await _kartaMapDbAccess.GetAllMapsKirjaPageIsMarkedIn(id); foreach (KartaMapMarkerQueryResult curMapQueryResult in markerResult) { KartaMap map = await _kartaMapDbAccess.GetMapById(curMapQueryResult.MapId); foreach (KirjaPageMapMarker curMarker in map.KirjaPageMarker) { if (curMarker.PageId == id) { curMarker.PageName = pageName; } } await _kartaMapDbAccess.UpdateMap(map); } }
/// <summary> /// Adjustes map markers for a deleted chapters /// </summary> /// <param name="projectId">Project Id</param> /// <param name="deletedChapter">Deleted chapter number</param> /// <param name="minChapterNumber">Min Chapter number</param> /// <param name="maxChapterNumber">Max Chapter number</param> /// <param name="chapters">Chapters</param> /// <returns></returns> private async Task AdjustKartaMapMarkersForDeletedChapter(string projectId, int deletedChapter, int minChapterNumber, int maxChapterNumber, List <AikaChapter> chapters) { List <KartaMap> allMaps = await _kartaMapDbAccess.GetAllProjectMapsWithFullDetail(projectId); foreach (KartaMap curMap in allMaps) { bool anyChange = AdjustMapMarkerListForDeletedChapter(curMap.NpcMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters); anyChange = AdjustMapMarkerListForDeletedChapter(curMap.ItemMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange; anyChange = AdjustMapMarkerListForDeletedChapter(curMap.KirjaPageMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange; anyChange = AdjustMapMarkerListForDeletedChapter(curMap.QuestMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange; anyChange = AdjustMapMarkerListForDeletedChapter(curMap.MapChangeMarker, deletedChapter, minChapterNumber, maxChapterNumber, chapters) || anyChange; if (anyChange) { await _kartaMapDbAccess.UpdateMap(curMap); } } }
public async Task <IActionResult> UpdateMap(string id, string name) { // Validate data if (string.IsNullOrEmpty(name)) { return(StatusCode((int)HttpStatusCode.BadRequest)); } string validateResult = this.ValidateImageUploadData(); if (validateResult != null) { return(StatusCode((int)HttpStatusCode.BadRequest, _localizer[validateResult])); } // Get Old Data KartaMap map = await _mapDbAccess.GetMapById(id); int oldWidth = map.Width; int oldHeight = map.Height; // Rename map bool nameChanged = map.Name != name; map.Name = name; await this.SetModifiedData(_userManager, map); // Rebuild images try { _mapImageAccess.SaveMapImagesForRollback(map.Id); await _imageProcessor.ProcessMapImage(map, Request.Form.Files[0]); } catch (Exception ex) { _mapImageAccess.RollbackMapImages(map.Id); _logger.LogError(ex, "Could not process map image."); return(StatusCode((int)HttpStatusCode.InternalServerError)); } // Scale Map Markers float scaleX = (int)((float)map.Width / oldWidth); float scaleY = (int)((float)map.Height / oldHeight); foreach (MapMarker curMarker in map.NpcMarker) { ScaleMapMarker(curMarker, scaleX, scaleY); } foreach (MapMarker curMarker in map.ItemMarker) { ScaleMapMarker(curMarker, scaleX, scaleY); } foreach (MapMarker curMarker in map.KirjaPageMarker) { ScaleMapMarker(curMarker, scaleX, scaleY); } foreach (MapMarker curMarker in map.QuestMarker) { ScaleMapMarker(curMarker, scaleX, scaleY); } foreach (MapMarker curMarker in map.MapChangeMarker) { ScaleMapMarker(curMarker, scaleX, scaleY); } foreach (MapMarker curMarker in map.NoteMarker) { ScaleMapMarker(curMarker, scaleX, scaleY); } try { await _mapDbAccess.UpdateMap(map); } catch (Exception ex) { _mapImageAccess.RollbackMapImages(map.Id); _logger.LogError(ex, "Could not update map image."); return(StatusCode((int)HttpStatusCode.InternalServerError)); } if (nameChanged) { await SyncMapNameToMarkers(id, name); } // Clean rollback data _mapImageAccess.CleanRollbackMapImages(map.Id); await _timelineService.AddTimelineEntry(TimelineEvent.KartaMapUpdated, name, id); return(Ok(id)); }
/// <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); } }