public async Task <IActionResult> AddNode(int projectId, [FromBody] AddNodeViewModel model) { if (String.IsNullOrEmpty(model.Data) && model.Data != null) { BadRequest("Manque data"); } if (String.IsNullOrEmpty(model.TypeOfData) && model.TypeOfData != null) { BadRequest("Manque type de donée"); } bool userCanModifyProject = await UserCanModifyProject(projectId); if (!userCanModifyProject) { return(StatusCode(403, "Access Denied !")); } string r = _dGraphGateway.GetNodeBy(projectId, model.Data, model.TypeOfData); dynamic nodeDGraph = JsonConvert.DeserializeObject(r); bool nodeExists = nodeDGraph.FindNode.Count > 0; if (nodeExists) { return(BadRequest("Node already exists")); } string jsonNodeCreated = await _dGraphGateway.AddNode(projectId, HttpContext.User.Identity.Name, model.Data, model.Note, model.Source, model.TypeOfData); // HUB PROJECT ACTU return(Ok(jsonNodeCreated)); }
private void StopDraggingPin() { if (IsDraggingPin) { if (PreviewConnection.IsValidDrop && PreviewConnection.DropTarget != null) { ConnectPins(DraggedPin, PreviewConnection.DropTarget); } else { CKlaxScriptNodeQueryContext queryContext = new CKlaxScriptNodeQueryContext { InputPinType = DraggedPin.GetPinType(), IsExecPin = DraggedPin.IsExecutionPin(), QueryObject = ScriptGraph.ScriptableObject, }; m_addNodePoint = ((NodeGraphView)Content).GetPasteReferenceLocation(); AddNodeViewModel.SetContext(queryContext); AddNodeViewModel.IsOpen = true; m_addNodeContextPin = DraggedPin; } } PreviewConnection.IsVisible = false; PreviewConnection.IsValidDrop = false; PreviewConnection.DropTarget = null; IsDraggingPin = false; Mouse.OverrideCursor = null; }
public async Task AddNodeShouldBeReturnSucess() { AddNodeViewModel body = new AddNodeViewModel() { Value = 10 }; var response = await _fixture.Client.PostAsJsonAsync("api/binarytree/addnode", body); Assert.True(response.IsSuccessStatusCode); }
private void OnPreviewMouseUp(object e) { MouseButtonEventArgs args = (MouseButtonEventArgs)e; if (args.ChangedButton == MouseButton.Right && ScriptGraph != null) { Vector delta = m_mouseDownPoint - args.GetPosition(null); if (delta.LengthSquared < m_nodeMoveThresholdSq) { m_addNodeContextPin = null; AddNodeViewModel.SetContext(new CKlaxScriptNodeQueryContext(ScriptGraph.ScriptableObject)); AddNodeViewModel.IsOpen = true; } } }
public async Task Post_AddNodeReturnsSuccessAndCorrectContent() { var client = _factory.CreateClient(); var vm = new AddNodeViewModel(); vm.SigmaGraphJson = SigmaGraphFactory.GetValidSigmaGraphJson(); vm.Value = 5; var json = JsonConvert.SerializeObject(vm); var content = new StringContent(json, Encoding.UTF8, "application/x-ww-form-urlencoded"); HttpResponseMessage response = await client.PostAsync("/AddNode", content); response.EnsureSuccessStatusCode(); Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType.ToString()); }
public async Task Post_AddNodeRedirectsToIndexOnInvalidModel(string url) { var client = _factory.CreateClient( new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); //empty view model var vm = new AddNodeViewModel(); var json = JsonConvert.SerializeObject(vm); var content = new StringContent(json, Encoding.UTF8, "application/x-ww-form-urlencoded"); HttpResponseMessage response = await client.PostAsync(url, content); Assert.Equal(HttpStatusCode.Redirect, response.StatusCode); }
public IActionResult AddNode(AddNodeViewModel addNodeViewModel) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } ITree tree = null; if (String.IsNullOrEmpty(addNodeViewModel.SigmaGraphJson)) { tree = redBlackTreeInitializer.InitTree(); } else { tree = treeToJsonConverter.JsonToTree(addNodeViewModel.SigmaGraphJson); } tree.InsertNode(addNodeViewModel.Value.Value); return(Content(treeToJsonConverter.ToSigmaJson(tree))); }
public IActionResult AddNode(AddNodeViewModel addNodeViewModel) { _binarySearchTreeService.AddNode(new Node(addNodeViewModel.Value)); return(Ok()); }
public async Task <IActionResult> Add(AddNodeViewModel viewModel) { ViewData["Title"] = "Pridėti gamintoją"; if (ModelState.IsValid) { var endpointValidationResult = await viewModel.ValidateEndpoint(); if (!endpointValidationResult.isSuccessful) { ModelState.AddModelError("HealthEndPoint", endpointValidationResult.ToStringErrors()); return(View(viewModel)); } var ruleValidationResult = viewModel.ValidateRule(); if (!ruleValidationResult.isSuccessful) { ModelState.AddModelError("Rule", ruleValidationResult.ToStringErrors()); return(View(viewModel)); } var node = (Node)viewModel; node.SetRuleFromString(viewModel.Rule); var validationResult = node.ValidateInputDataTypes(); if (!validationResult.isSuccessful) { ModelState.AddModelError("", validationResult.ToStringErrors()); return(View(viewModel)); } var nodesResult = await _nodesService.GetAllNodes(); var nodes = nodesResult.result; if (nodes.Any(x => x.Rule.ToStringFull() == node.Rule.ToStringFull())) { ModelState.AddModelError("Rule", "Taisyklė jau pridėta."); return(View(viewModel)); } //Check input type compatibility var nodesWithOutputsSameAsInput = new List <Node>(); foreach (var inputDataType in node.InputDataType) { var temp = nodes.Where(x => node.Rule.LeftSide.Contains(x.Rule.RightSide)).ToList(); nodesWithOutputsSameAsInput.AddRange(temp); } if (nodesWithOutputsSameAsInput.Any()) { var message = ""; foreach (var node1 in nodesWithOutputsSameAsInput) { var node1RightSide = node1.Rule.RightSide; var nodeLeftSide = node.Rule.LeftSide; var commonIndex = nodeLeftSide.IndexOf(node1RightSide); if (node.InputDataType[commonIndex] != node1.OutputDataType) { message += "Antecedento '" + nodeLeftSide[commonIndex] + "' tipas turi būti '" + node1.OutputDataType.DisplayName() + "'" + System.Environment.NewLine; } } if (!String.IsNullOrEmpty(message)) { ModelState.AddModelError("", message); return(View(viewModel)); } } //Check output type compatibilty var nodesWithInputsSameAsOutput = nodes.Where(x => x.Rule.LeftSide.Contains(node.Rule.RightSide)).ToList(); if (nodesWithInputsSameAsOutput.Any()) { var message = ""; foreach (var node1 in nodesWithInputsSameAsOutput) { var nodeRightSide = node.Rule.RightSide; var node1LeftSide = node1.Rule.LeftSide; var commonIndex = node1LeftSide.IndexOf(nodeRightSide); if (node1.InputDataType[commonIndex] != node.OutputDataType) { message += "Konsekvento '" + nodeRightSide + "' tipas turi būti '" + node1.InputDataType[commonIndex].DisplayName() + "'" + System.Environment.NewLine; } } if (!String.IsNullOrEmpty(message)) { ModelState.AddModelError("", message); return(View(viewModel)); } } await _nodesService.AddNode(node); TempData["SuccessMessage"] = "Gamintojas sėkmingai pridėtas."; return(RedirectToAction("Index")); } return(View(viewModel)); }