public async Task <IActionResult> CreateUser([FromBody] UserCreateRequest userRequest) { if (string.IsNullOrEmpty(userRequest.Email) || string.IsNullOrEmpty(userRequest.DisplayName) || string.IsNullOrEmpty(userRequest.Password)) { return(StatusCode((int)HttpStatusCode.BadRequest)); } GoNorthUser user = new GoNorthUser { UserName = userRequest.Email, Email = userRequest.Email, DisplayName = userRequest.DisplayName }; IdentityResult result = await _userCreator.CreateUser(Url, Request.Scheme, userRequest.DisplayName, userRequest.Email, userRequest.Password, string.Empty); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _timelineService.AddTimelineEntry(TimelineEvent.NewUser, user.Email); return(Ok(user.Email)); } else { return(ReturnErrorResultFromIdentityResult(result)); } }
public async Task <IActionResult> CreatePage([FromBody] PageRequest page) { if (string.IsNullOrEmpty(page.Name)) { return(StatusCode((int)HttpStatusCode.BadRequest)); } try { GoNorthProject project = await _projectDbAccess.GetDefaultProject(); KirjaPage newPage = new KirjaPage(); newPage.ProjectId = project.Id; newPage.Name = page.Name; newPage.Content = page.Content; newPage.Attachments = new List <KirjaPageAttachment>(); _pageParserService.ParsePage(newPage); await this.SetModifiedData(_userManager, newPage); newPage = await _pageDbAccess.CreatePage(newPage); await _timelineService.AddTimelineEntry(TimelineEvent.KirjaPageCreated, newPage.Name, newPage.Id); return(Ok(newPage)); } catch (Exception ex) { _logger.LogError(ex, "Could not create page {0}", page.Name); return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public async Task <IActionResult> SaveDefaultExportTemplate(TemplateType templateType, [FromBody] string code) { GoNorthProject project = await _projectDbAccess.GetDefaultProject(); ExportTemplate template = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, templateType); template = await SaveExportTemplate(project, template, code); await _timelineService.AddTimelineEntry(TimelineEvent.ExportDefaultTemplateUpdated, ((int)templateType).ToString()); return(Ok(template)); }
public async Task <IActionResult> CreateTaskBoard([FromBody] TaskBoard board) { // Validate Data if (string.IsNullOrEmpty(board.Name)) { return(StatusCode((int)HttpStatusCode.BadRequest)); } // Create Task Board TaskBoard newBoard = new TaskBoard(); newBoard.IsClosed = false; newBoard.Name = board.Name; newBoard.PlannedStart = board.PlannedStart; newBoard.PlannedEnd = board.PlannedEnd; newBoard.TaskGroups = new List <TaskGroup>(); await this.SetModifiedData(_userManager, newBoard); GoNorthProject project = await _projectDbAccess.GetDefaultProject(); newBoard.ProjectId = project.Id; try { newBoard = await _taskBoardDbAccess.CreateTaskBoard(newBoard); } catch (Exception ex) { _logger.LogError(ex, "Could not create task board."); return(StatusCode((int)HttpStatusCode.InternalServerError)); } // Add Timeline entry try { await _timelineService.AddTimelineEntry(TimelineEvent.TaskBoardCreated, newBoard.Id, newBoard.Name); } catch (Exception ex) { _logger.LogError(ex, "Could not create task board create timeline entry."); await _taskBoardDbAccess.DeleteTaskBoard(newBoard); return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok(newBoard.Id)); }
public async Task <IActionResult> CreateProject([FromBody] GoNorthProject project) { if (string.IsNullOrEmpty(project.Name)) { return(BadRequest()); } try { project = await _projectDbAccess.CreateProject(project); await _timelineService.AddTimelineEntry(null, TimelineEvent.ProjectCreated, project.Name); return(Ok(project.Id)); } catch (Exception ex) { _logger.LogError(ex, "Could not create project {0}", project.Name); return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
/// <summary> /// Checks an npc for update /// </summary> /// <param name="exportSnippet">Export Snippet</param> /// <param name="objectId">Object Id</param> /// <param name="timelineEvent">Timeline Event</param> /// <returns>Result of update</returns> private async Task <FlexFieldObject> CheckNpcForUpdate(ObjectExportSnippet exportSnippet, string objectId, TimelineEvent timelineEvent) { KortistoNpc npc = await _npcDbAccess.GetFlexFieldObjectById(objectId); if (npc == null) { return(null); } await _timelineService.AddTimelineEntry(exportSnippet.ProjectId, timelineEvent, exportSnippet.SnippetName, npc.Name, npc.Id); CompareResult result = await _implementationStatusComparer.CompareNpc(npc.Id, npc); if (result.CompareDifference != null && result.CompareDifference.Count > 0) { npc.IsImplemented = false; await _npcDbAccess.UpdateFlexFieldObject(npc); } return(npc); }
public async Task <IActionResult> FlagNpcAsImplemented(string npcId) { // Check Data KortistoNpc npc = await _npcDbAccess.GetFlexFieldObjectById(npcId); if (npc == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } // Flag npc as implemented npc.IsImplemented = true; await _npcSnapshotDbAccess.SaveSnapshot(npc); await _npcDbAccess.UpdateFlexFieldObject(npc); // Add Timeline entry await _timelineService.AddTimelineEntry(TimelineEvent.ImplementedNpc, npc.Id, npc.Name); return(Ok()); }
public async Task <IActionResult> CreateMap(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])); } // Prepare Map KartaMap map = new KartaMap(); map.Id = Guid.NewGuid().ToString(); map.Name = name; await this.SetModifiedData(_userManager, map); GoNorthProject project = await _projectDbAccess.GetDefaultProject(); map.ProjectId = project.Id; // Process Map try { await _imageProcessor.ProcessMapImage(map, Request.Form.Files[0]); } catch (Exception ex) { _logger.LogError(ex, "Could not process map image."); _mapImageAccess.DeleteMapFolder(map.Id); return(StatusCode((int)HttpStatusCode.InternalServerError)); } // Save Map try { await _mapDbAccess.CreateMap(map); } catch (Exception ex) { _logger.LogError(ex, "Could not save map."); _mapImageAccess.DeleteMapFolder(map.Id); return(StatusCode((int)HttpStatusCode.InternalServerError)); } await _timelineService.AddTimelineEntry(TimelineEvent.KartaMapCreated, map.Name, map.Id); return(Ok(map.Id)); }
public async Task <IActionResult> FlagNpcAsImplemented(string npcId) { // Check Data KortistoNpc npc = await _npcDbAccess.GetFlexFieldObjectById(npcId); if (npc == null) { return(NotFound()); } // Flag npc as implemented npc.IsImplemented = true; await _npcSnapshotDbAccess.SaveSnapshot(npc); await _npcDbAccess.UpdateFlexFieldObject(npc); await FlagObjectExportSnippetsAsImplemented(npc.Id); await FlagStateMachinesAsImplemented(npc.Id); // Add Timeline entry await _timelineService.AddTimelineEntry(npc.ProjectId, TimelineEvent.ImplementedNpc, npc.Id, npc.Name); return(Ok()); }
public async Task <IActionResult> CreateFolder([FromBody] FolderRequest folder) { if (string.IsNullOrEmpty(folder.Name)) { return(StatusCode((int)HttpStatusCode.BadRequest)); } try { GoNorthProject project = await _projectDbAccess.GetDefaultProject(); FlexFieldFolder newFolder = new FlexFieldFolder { ProjectId = project.Id, ParentFolderId = folder.ParentId, Name = folder.Name, Description = folder.Description }; newFolder = await _folderDbAccess.CreateFolder(newFolder); await _timelineService.AddTimelineEntry(FolderCreatedEvent, folder.Name); return(Ok(newFolder.Id)); } catch (Exception ex) { _logger.LogError(ex, "Could not create folder {0}", folder.Name); return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public async Task <IActionResult> SaveDialog(string relatedObjectId, [FromBody] TaleDialog dialog) { // Validate data if (string.IsNullOrEmpty(relatedObjectId)) { return(BadRequest()); } List <KortistoNpc> npcNames = await _npcDbAccess.ResolveFlexFieldObjectNames(new List <string> { relatedObjectId }); if (npcNames.Count == 0) { return(BadRequest()); } string npcName = npcNames[0].Name; // Update or create dialog TaleDialog existingDialog = await _taleDbAccess.GetDialogByRelatedObjectId(relatedObjectId); bool isCreate = false; if (existingDialog == null) { KortistoNpc npc = await _npcDbAccess.GetFlexFieldObjectById(relatedObjectId); existingDialog = new TaleDialog(); existingDialog.RelatedObjectId = relatedObjectId; existingDialog.ProjectId = npc.ProjectId; isCreate = true; } existingDialog.Link = dialog.Link != null ? dialog.Link : new List <NodeLink>(); existingDialog.PlayerText = dialog.PlayerText != null ? dialog.PlayerText : new List <TextNode>(); existingDialog.NpcText = dialog.NpcText != null ? dialog.NpcText : new List <TextNode>(); existingDialog.Choice = dialog.Choice != null ? dialog.Choice : new List <TaleChoiceNode>(); existingDialog.Action = dialog.Action != null ? dialog.Action : new List <ActionNode>(); existingDialog.Condition = dialog.Condition != null ? dialog.Condition : new List <ConditionNode>(); existingDialog.Reference = dialog.Reference != null ? dialog.Reference : new List <ReferenceNode>(); await this.SetModifiedData(_userManager, existingDialog); // Save Data if (isCreate) { existingDialog = await _taleDbAccess.CreateDialog(existingDialog); await _timelineService.AddTimelineEntry(existingDialog.ProjectId, TimelineEvent.TaleDialogCreated, relatedObjectId, npcName); } else { // Check implementation state if (existingDialog.IsImplemented) { CompareResult result = await _implementationStatusComparer.CompareDialog(existingDialog.Id, existingDialog); if (result.CompareDifference != null && result.CompareDifference.Count > 0) { existingDialog.IsImplemented = false; } } await _taleDbAccess.UpdateDialog(existingDialog); await _timelineService.AddTimelineEntry(existingDialog.ProjectId, TimelineEvent.TaleDialogUpdated, relatedObjectId, npcName); } return(Ok(existingDialog)); }
public async Task <IActionResult> SaveChapterOverview([FromBody] AikaChapterOverview overview) { // Check Data if (overview.Chapter == null) { overview.Chapter = new List <AikaChapter>(); } if (overview.Link == null) { overview.Link = new List <NodeLink>(); } // Get Current Overview GoNorthProject defaultProject = await _projectDbAccess.GetDefaultProject(); AikaChapterOverview chapterOverview = await _chapterOverviewDbAccess.GetChapterOverviewByProjectId(defaultProject.Id); bool overviewExisted = true; List <AikaChapterDetail> chapterDetailsToDelete = new List <AikaChapterDetail>(); List <AikaChapterDetail> chapterDetailsToRename = new List <AikaChapterDetail>(); List <int> deletedChapterNumbers = new List <int>(); if (chapterOverview == null) { chapterOverview = new AikaChapterOverview(); chapterOverview.ProjectId = defaultProject.Id; overviewExisted = false; } else { // Check deleted chapter numbers deletedChapterNumbers = chapterOverview.Chapter.Where(c => !overview.Chapter.Any(uc => uc.ChapterNumber == c.ChapterNumber)).Select(c => c.ChapterNumber).ToList(); // Check deleted chapters List <AikaChapter> deletedChapters = chapterOverview.Chapter.Where(c => !overview.Chapter.Any(uc => uc.Id == c.Id)).ToList(); foreach (AikaChapter curDeletedChapter in deletedChapters) { if (string.IsNullOrEmpty(curDeletedChapter.DetailViewId)) { continue; } AikaChapterDetail deletedChapterDetail = await _chapterDetailDbAccess.GetChapterDetailById(curDeletedChapter.DetailViewId); if ((deletedChapterDetail.Detail != null && deletedChapterDetail.Detail.Count > 0) || (deletedChapterDetail.Quest != null && deletedChapterDetail.Quest.Count > 0) || (deletedChapterDetail.AllDone != null && deletedChapterDetail.AllDone.Count > 0) || (deletedChapterDetail.Finish != null && deletedChapterDetail.Finish.Count > 0)) { _logger.LogInformation("Tried to delete non empty chapter"); return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CanNotDeleteNonEmptyChapter"].Value)); } chapterDetailsToDelete.Add(deletedChapterDetail); } // Check renamed chapters List <AikaChapter> renamedChapters = overview.Chapter.Where(c => chapterOverview.Chapter.Any(uc => uc.Id == c.Id && uc.Name != c.Name)).ToList(); foreach (AikaChapter curRenamedChapter in renamedChapters) { if (string.IsNullOrEmpty(curRenamedChapter.DetailViewId)) { continue; } AikaChapterDetail renamedChapterDetail = await _chapterDetailDbAccess.GetChapterDetailById(curRenamedChapter.DetailViewId); renamedChapterDetail.Name = curRenamedChapter.Name; chapterDetailsToRename.Add(renamedChapterDetail); } } // Update Data chapterOverview.Link = overview.Link != null ? overview.Link : new List <NodeLink>(); chapterOverview.Chapter = overview.Chapter != null ? overview.Chapter : new List <AikaChapter>(); // Create Detail Views _logger.LogInformation("Creating chapter detail views"); bool errorOccured = false; List <AikaChapterDetail> createdChapterDetails = new List <AikaChapterDetail>(); foreach (AikaChapter curChapter in chapterOverview.Chapter) { if (string.IsNullOrEmpty(curChapter.DetailViewId)) { try { AikaChapterDetail newChapterDetail = await CreateNewChapterDetail(defaultProject.Id, curChapter.Id, curChapter.Name); curChapter.DetailViewId = newChapterDetail.Id; createdChapterDetails.Add(newChapterDetail); } catch (Exception ex) { _logger.LogError(ex, "Could not create chapter detail view."); errorOccured = true; break; } } } // Rollback on error if (errorOccured) { foreach (AikaChapterDetail curDetail in createdChapterDetails) { await _chapterDetailDbAccess.DeleteChapterDetail(curDetail); } return(StatusCode((int)HttpStatusCode.InternalServerError)); } // Save Chapter overview await this.SetModifiedData(_userManager, chapterOverview); if (overviewExisted) { await _chapterOverviewDbAccess.UpdateChapterOverview(chapterOverview); } else { chapterOverview = await _chapterOverviewDbAccess.CreateChapterOverview(chapterOverview); } // Rename Chapter details foreach (AikaChapterDetail curRenamedChapter in chapterDetailsToRename) { await _chapterDetailDbAccess.UpdateChapterDetail(curRenamedChapter); } // Remove Chapter Details for deleted chapters foreach (AikaChapterDetail curDeletedChapterDetail in chapterDetailsToDelete) { await _chapterDetailDbAccess.DeleteChapterDetail(curDeletedChapterDetail); } // Adjust Aika markers for deleted chapters int minChapterNumber = chapterOverview.Chapter.Min(c => c.ChapterNumber); int maxChapterNumber = chapterOverview.Chapter.Max(c => c.ChapterNumber); foreach (int curChapterNumber in deletedChapterNumbers) { await AdjustKartaMapMarkersForDeletedChapter(defaultProject.Id, curChapterNumber, minChapterNumber, maxChapterNumber, chapterOverview.Chapter); } // Timeline Entry await _timelineService.AddTimelineEntry(TimelineEvent.AikaChapterOverviewUpdated); return(Ok(chapterOverview)); }
public async Task <IActionResult> SaveStateMachine(string relatedObjectId, [FromBody] StateMachine stateMachine) { // Validate data if (string.IsNullOrEmpty(relatedObjectId)) { return(BadRequest()); } List <KortistoNpc> npcNames = await _npcDbAccess.ResolveFlexFieldObjectNames(new List <string> { relatedObjectId }); bool isTemplateMode = false; string npcName = null; if (npcNames.Count == 1) { npcName = npcNames[0].Name; } else { List <KortistoNpc> npcTemplatesNames = await _npcTemplateDbAccess.ResolveFlexFieldObjectNames(new List <string> { relatedObjectId }); if (npcTemplatesNames.Count == 1) { npcName = npcTemplatesNames[0].Name; isTemplateMode = true; } } if (string.IsNullOrEmpty(npcName)) { return(BadRequest()); } // Update or create state machine StateMachine existingStateMachine = await _stateMachineDbAccess.GetStateMachineByRelatedObjectId(relatedObjectId); bool isCreate = false; if (existingStateMachine == null) { KortistoNpc npc; if (!isTemplateMode) { npc = await _npcDbAccess.GetFlexFieldObjectById(relatedObjectId); } else { npc = await _npcTemplateDbAccess.GetFlexFieldObjectById(relatedObjectId); } existingStateMachine = new StateMachine(); existingStateMachine.RelatedObjectId = relatedObjectId; existingStateMachine.ProjectId = npc.ProjectId; isCreate = true; } existingStateMachine.Start = stateMachine.Start != null ? stateMachine.Start : new List <StateMachineStartEnd>(); existingStateMachine.State = stateMachine.State != null ? stateMachine.State : new List <StateMachineState>(); existingStateMachine.End = stateMachine.End != null ? stateMachine.End : new List <StateMachineStartEnd>(); existingStateMachine.Link = stateMachine.Link != null ? stateMachine.Link : new List <StateTransition>(); await this.SetModifiedData(_userManager, existingStateMachine); await SetImplementationStatusOfRelatedObject(existingStateMachine); // Save Data if (isCreate) { existingStateMachine = await _stateMachineDbAccess.CreateStateMachine(existingStateMachine); await _timelineService.AddTimelineEntry(existingStateMachine.ProjectId, TimelineEvent.StateMachineCreated, relatedObjectId, npcName); } else { await _stateMachineDbAccess.UpdateStateMachine(existingStateMachine); await _timelineService.AddTimelineEntry(existingStateMachine.ProjectId, TimelineEvent.StateMachineUpdated, relatedObjectId, npcName); } return(Ok(existingStateMachine)); }