/// <summary> /// Returns the current user project /// </summary> /// <returns>Current user project</returns> public async Task <GoNorthProject> GetUserProject() { string userId = _userManager.GetUserId(_httpContext.HttpContext.User); UserSelectedProject selectedProject = await _projectDbAccess.GetUserSelectedProject(userId); GoNorthProject project = null; if (selectedProject != null) { project = await _projectDbAccess.GetProjectById(selectedProject.ProjectId); } if (project == null) { project = await _projectDbAccess.GetDefaultProject(); } return(project); }
/// <summary> /// Fills the modified data for the response /// </summary> /// <param name="response">Response to send</param> /// <param name="currentUser">Current user</param> /// <returns>Task</returns> private async Task FillModifiedData(PersonalDataResponse response, GoNorthUser currentUser) { response.ModifiedData = new List <TrimmedModifiedData>(); List <AikaQuest> quests = await _questDbAccess.GetQuestsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(quests.Select(p => new TrimmedModifiedData { ObjectType = "Quest", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <AikaQuest> questRecycleBin = await _questDbAccess.GetRecycleBinQuestsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(questRecycleBin.Select(p => new TrimmedModifiedData { ObjectType = "QuestRecycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <AikaQuest> questImplementationSnapshots = await _questImplementationSnapshotDbAccess.GetSnapshotsModifiedByUsers(currentUser.Id); response.ModifiedData.AddRange(questImplementationSnapshots.Select(p => new TrimmedModifiedData { ObjectType = "QuestImplementationSnapshot", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <AikaChapterDetail> chapterDetail = await _chapterDetailDbAccess.GetChapterDetailsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(chapterDetail.Select(p => new TrimmedModifiedData { ObjectType = "ChapterDetail", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <AikaChapterDetail> chapterDetailRecycleBin = await _chapterDetailDbAccess.GetRecycleBinChapterDetailsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(chapterDetailRecycleBin.Select(p => new TrimmedModifiedData { ObjectType = "ChapterDetailRecycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <AikaChapterOverview> chapterOverview = await _chapterOverviewDbAccess.GetChapterOverviewByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(chapterOverview.Select(p => new TrimmedModifiedData { ObjectType = "ChapterOverview", Name = "ChapterOverview", ModifiedDate = p.ModifiedOn })); List <AikaChapterOverview> chapterOverviewRecycleBin = await _chapterOverviewDbAccess.GetRecycleBinChapterOverviewByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(chapterOverviewRecycleBin.Select(p => new TrimmedModifiedData { ObjectType = "ChapterOverviewRecycleBin", Name = "ChapterOverview", ModifiedDate = p.ModifiedOn })); List <EvneSkill> skills = await _skillDbAccess.GetFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(skills.Select(p => new TrimmedModifiedData { ObjectType = "Skill", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <EvneSkill> skillsRecyleBin = await _skillDbAccess.GetRecycleBinFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(skillsRecyleBin.Select(p => new TrimmedModifiedData { ObjectType = "SkillRecycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <EvneSkill> skillsImplementationSnapshots = await _skillImplementationSnapshotDbAccess.GetSnapshotsModifiedByUsers(currentUser.Id); response.ModifiedData.AddRange(skillsImplementationSnapshots.Select(p => new TrimmedModifiedData { ObjectType = "SkillImplementationSnapshot", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <FlexFieldImportFieldValuesResultLog> skillsFieldValuesLogs = await _skillImportFieldValuesLogDbAccess.GetImportLogsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(skillsFieldValuesLogs.Select(p => new TrimmedModifiedData { ObjectType = "SkillFieldValueImportLog", Name = p.FileName, ModifiedDate = p.ModifiedOn })); List <EvneSkill> skillTemplates = await _skillTemplateDbAccess.GetFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(skillTemplates.Select(p => new TrimmedModifiedData { ObjectType = "SkillTemplate", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <EvneSkill> skillsTemplateRecyleBin = await _skillTemplateDbAccess.GetRecycleBinFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(skillsTemplateRecyleBin.Select(p => new TrimmedModifiedData { ObjectType = "SkillTemplateRecycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <KortistoNpc> npcs = await _npcDbAccess.GetFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(npcs.Select(p => new TrimmedModifiedData { ObjectType = "Npc", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <KortistoNpc> npcsRecycleBin = await _npcDbAccess.GetRecycleBinFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(npcsRecycleBin.Select(p => new TrimmedModifiedData { ObjectType = "NpcRecycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <KortistoNpc> npcImplementationSnapshots = await _npcImplementationSnapshotDbAccess.GetSnapshotsModifiedByUsers(currentUser.Id); response.ModifiedData.AddRange(npcImplementationSnapshots.Select(p => new TrimmedModifiedData { ObjectType = "NpcImplementationSnapshot", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <FlexFieldImportFieldValuesResultLog> npcsFieldValuesLogs = await _npcImportFieldValuesLogDbAccess.GetImportLogsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(npcsFieldValuesLogs.Select(p => new TrimmedModifiedData { ObjectType = "NpcFieldValueImportLog", Name = p.FileName, ModifiedDate = p.ModifiedOn })); List <KortistoNpc> npcTemplates = await _npcTemplateDbAccess.GetFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(npcTemplates.Select(p => new TrimmedModifiedData { ObjectType = "NpcTemplate", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <KortistoNpc> npcTemplatesRecycleBin = await _npcTemplateDbAccess.GetRecycleBinFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(npcTemplatesRecycleBin.Select(p => new TrimmedModifiedData { ObjectType = "NpcTemplateRecycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <StyrItem> items = await _itemDbAccess.GetFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(items.Select(p => new TrimmedModifiedData { ObjectType = "Item", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <StyrItem> itemsRecyleBin = await _itemDbAccess.GetRecycleBinFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(itemsRecyleBin.Select(p => new TrimmedModifiedData { ObjectType = "ItemReycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <StyrItem> itemImplementationSnapshots = await _itemImplementationSnapshotDbAccess.GetSnapshotsModifiedByUsers(currentUser.Id); response.ModifiedData.AddRange(itemImplementationSnapshots.Select(p => new TrimmedModifiedData { ObjectType = "ItemImplementationSnapshot", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <FlexFieldImportFieldValuesResultLog> itemsFieldValuesLogs = await _itemImportFieldValuesLogDbAccess.GetImportLogsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(itemsFieldValuesLogs.Select(p => new TrimmedModifiedData { ObjectType = "ItemFieldValueImportLog", Name = p.FileName, ModifiedDate = p.ModifiedOn })); List <StyrItem> itemTemplates = await _itemTemplateDbAccess.GetFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(itemTemplates.Select(p => new TrimmedModifiedData { ObjectType = "ItemTemplate", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <StyrItem> itemTemplatesRecyleBin = await _itemTemplateDbAccess.GetRecycleBinFlexFieldObjectsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(itemTemplatesRecyleBin.Select(p => new TrimmedModifiedData { ObjectType = "ItemTemplateReycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <ExportTemplate> exportTemplates = await _exportTemplateDbAccess.GetExportTemplatesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(exportTemplates.Select(p => new TrimmedModifiedData { ObjectType = "ExportTemplate", Name = "Template " + p.TemplateType.ToString() + " " + p.Category.ToString(), ModifiedDate = p.ModifiedOn })); List <ExportTemplate> exportTemplatesRecycleBin = await _exportTemplateDbAccess.GetRecycleBinExportTemplatesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(exportTemplatesRecycleBin.Select(p => new TrimmedModifiedData { ObjectType = "ExportTemplateRecycleBin", Name = "Template " + p.TemplateType.ToString() + " " + p.Category.ToString(), ModifiedDate = p.ModifiedOn })); List <IncludeExportTemplate> includeExportTemplates = await _includeExportTemplateDbAccess.GetIncludeTemplatesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(includeExportTemplates.Select(p => new TrimmedModifiedData { ObjectType = "IncludeExportTemplate", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <IncludeExportTemplate> includeExportTemplatesRecycleBin = await _includeExportTemplateDbAccess.GetRecycleBinIncludeTemplatesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(includeExportTemplatesRecycleBin.Select(p => new TrimmedModifiedData { ObjectType = "IncludeExportTemplateRecycleBin", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <ObjectExportSnippet> objectExportSnippets = await _objectExportSnippetDbAccess.GetExportSnippetByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(objectExportSnippets.Select(p => new TrimmedModifiedData { ObjectType = "ObjectExportSnippet", Name = p.SnippetName, ModifiedDate = p.ModifiedOn })); List <KartaMap> maps = await _mapDbAccess.GetMapsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(maps.Select(p => new TrimmedModifiedData { ObjectType = "Map", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <KirjaPage> pages = await _pageDbAccess.GetPagesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(pages.Select(p => new TrimmedModifiedData { ObjectType = "WikiPage", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <KirjaPageVersion> pageVersions = await _pageVersionDbAccess.GetPageVersionsByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(pageVersions.Select(p => new TrimmedModifiedData { ObjectType = "WikiPageVersion", Name = string.Format("{0} #{1}", p.Name, p.VersionNumber), ModifiedDate = p.ModifiedOn })); List <TaleDialog> dialogs = await _taleDbAccess.GetDialogsByModifiedUser(currentUser.Id); Dictionary <string, KortistoNpc> dialogNpcs = (await _npcDbAccess.ResolveFlexFieldObjectNames(dialogs.Select(n => n.RelatedObjectId).ToList())).ToDictionary(n => n.Id); foreach (TaleDialog curDialog in dialogs) { string npcName = "DELETED"; if (dialogNpcs.ContainsKey(curDialog.RelatedObjectId)) { npcName = dialogNpcs[curDialog.RelatedObjectId].Name; } response.ModifiedData.Add(new TrimmedModifiedData { ObjectType = "Dialog", Name = npcName, ModifiedDate = curDialog.ModifiedOn }); } List <TaleDialog> dialogsRecyleBin = await _taleDbAccess.GetRecycleBinDialogsByModifiedUser(currentUser.Id); Dictionary <string, KortistoNpc> dialogRecyleBinNpcs = (await _npcDbAccess.ResolveRecycleBinFlexFieldObjectNames(dialogsRecyleBin.Select(n => n.RelatedObjectId).ToList())).ToDictionary(n => n.Id); foreach (TaleDialog curDialog in dialogsRecyleBin) { string npcName = "DELETED"; if (dialogRecyleBinNpcs.ContainsKey(curDialog.RelatedObjectId)) { npcName = dialogRecyleBinNpcs[curDialog.RelatedObjectId].Name; } response.ModifiedData.Add(new TrimmedModifiedData { ObjectType = "DialogRecyleBin", Name = npcName, ModifiedDate = curDialog.ModifiedOn }); } List <TaleDialog> dialogsSnapshots = await _taleImplementationSnapshotDbAccess.GetSnapshotsModifiedByUsers(currentUser.Id); Dictionary <string, KortistoNpc> dialogSnapshotNpcs = (await _npcDbAccess.ResolveFlexFieldObjectNames(dialogsSnapshots.Select(n => n.RelatedObjectId).ToList())).ToDictionary(n => n.Id); foreach (TaleDialog curDialogSnapshot in dialogsSnapshots) { string npcName = "DELETED"; if (dialogNpcs.ContainsKey(curDialogSnapshot.RelatedObjectId)) { npcName = dialogNpcs[curDialogSnapshot.RelatedObjectId].Name; } response.ModifiedData.Add(new TrimmedModifiedData { ObjectType = "DialogSnapshot", Name = npcName, ModifiedDate = curDialogSnapshot.ModifiedOn }); } List <StateMachine> stateMachines = await _stateMachineDbAccess.GetStateMachinesByModifiedUser(currentUser.Id); Dictionary <string, KortistoNpc> stateMachineNpcs = (await _npcDbAccess.ResolveFlexFieldObjectNames(stateMachines.Select(n => n.RelatedObjectId).ToList())).ToDictionary(n => n.Id); foreach (StateMachine curStateMachine in stateMachines) { string npcName = "DELETED"; if (stateMachineNpcs.ContainsKey(curStateMachine.RelatedObjectId)) { npcName = stateMachineNpcs[curStateMachine.RelatedObjectId].Name; } response.ModifiedData.Add(new TrimmedModifiedData { ObjectType = "StateMachine", Name = npcName, ModifiedDate = curStateMachine.ModifiedOn }); } List <StateMachine> stateMachineSnapshots = await _stateMachineSnapsshotDbAccess.GetSnapshotsModifiedByUsers(currentUser.Id); Dictionary <string, KortistoNpc> stateMachineSnapshotNpcs = (await _npcDbAccess.ResolveFlexFieldObjectNames(stateMachineSnapshots.Select(n => n.RelatedObjectId).ToList())).ToDictionary(n => n.Id); foreach (StateMachine curStateMachine in stateMachineSnapshots) { string npcName = "DELETED"; if (stateMachineSnapshotNpcs.ContainsKey(curStateMachine.RelatedObjectId)) { npcName = stateMachineSnapshotNpcs[curStateMachine.RelatedObjectId].Name; } response.ModifiedData.Add(new TrimmedModifiedData { ObjectType = "StateMachineSnapshot", Name = npcName, ModifiedDate = curStateMachine.ModifiedOn }); } List <JsonConfigEntry> jsonConfigEntries = await _projectConfigDbAccess.GetJsonConfigEntriesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(jsonConfigEntries.Select(p => new TrimmedModifiedData { ObjectType = "JsonConfig", Name = p.Key, ModifiedDate = p.ModifiedOn })); List <MiscProjectConfig> miscConfigEntries = await _projectConfigDbAccess.GetMiscConfigEntriesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(miscConfigEntries.Select(p => new TrimmedModifiedData { ObjectType = "MiscConfig", Name = "Miscellaneous Config", ModifiedDate = p.ModifiedOn })); List <TaskBoard> taskBoards = await _taskBoardDbAccess.GetTaskBoardsByModifiedUser(currentUser.Id); foreach (TaskBoard curBoard in taskBoards) { if (curBoard.ModifiedBy == currentUser.Id) { response.ModifiedData.Add(new TrimmedModifiedData { ObjectType = "TaskBoard", Name = curBoard.Name, ModifiedDate = curBoard.ModifiedOn }); } List <TaskGroup> modifiedGroups = curBoard.TaskGroups.Where(t => t.ModifiedBy == currentUser.Id).ToList(); if (modifiedGroups.Count > 0) { response.ModifiedData.AddRange(modifiedGroups.Select(p => new TrimmedModifiedData { ObjectType = "TaskGroup", Name = p.Name, ModifiedDate = p.ModifiedOn })); } List <GoNorthTask> tasks = curBoard.TaskGroups.SelectMany(p => p.Tasks.Where(t => t.ModifiedBy == currentUser.Id)).ToList(); if (tasks.Count > 0) { response.ModifiedData.AddRange(tasks.Select(p => new TrimmedModifiedData { ObjectType = "Task", Name = p.Name, ModifiedDate = p.ModifiedOn })); } } List <GoNorthTaskType> taskGroupTypes = await _taskGroupTypeDbAccess.GetTaskTypesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(taskGroupTypes.Select(p => new TrimmedModifiedData { ObjectType = "TaskGroupType", Name = p.Name, ModifiedDate = p.ModifiedOn })); List <GoNorthTaskType> taskTypes = await _taskTypeDbAccess.GetTaskTypesByModifiedUser(currentUser.Id); response.ModifiedData.AddRange(taskTypes.Select(p => new TrimmedModifiedData { ObjectType = "TaskType", Name = p.Name, ModifiedDate = p.ModifiedOn })); response.SelectedProject = await _projectDbAccess.GetUserSelectedProject(currentUser.Id); }