Beispiel #1
0
        public IHttpActionResult CreateLink(CreateLink link)
        {
            var result = _linkRepository.CreateLink(link.SymbolicName, link.UserName);

            // TODO: Fill route
            return(Created("", result));
        }
Beispiel #2
0
        public ActionResult CreateLink([Bind(Include = "OriginID, TargetID, Type")] CreateLink Link)
        {
            List <object> errors = new List <object>();
            //ensure tar gets are in the same instance.
            var oNode = db.Nodes.Find(Link.OriginID);
            var tNode = db.Nodes.Find(Link.TargetID);

            if (oNode.InstanceID == tNode.InstanceID)
            {
                //ensure user is in an appropraite instance too.
                var username = Generic.GetUserName();
                var instance = db.Instances.Include("Members").First(x => x.InstanceID == oNode.InstanceID);
                if (instance.Members.Any(x => x.UserName == username))
                {
                    if (ModelState.IsValid)
                    {
                        db.Links.Add(new Models.Link(Link));
                        db.SaveChanges();
                        return(Json(Link));
                    }
                }
                ModelState.AddModelError("Error", "Invalid link");
            }
            else
            {
                ModelState.AddModelError("Error", "Invalid link");
            }

            return(Json(new { error = Generic.GetValidationErrors(ModelState) }));
        }
Beispiel #3
0
        public ActionResult CreateNode([Bind] CreateNode Node, int InstanceID)
        {
            if (ModelState.IsValid)
            {
                //make sure the layer exists in this instance.
                var Layer = db.Layers.DefaultIfEmpty(null).FirstOrDefault(x => x.InstanceID == Node.InstanceID && x.LayerID == Node.LayerID);
                if (Layer == null)
                {
                    ModelState.AddModelError("Layer", "Unable to find Layer.");
                    return(Json(new { error = Generic.GetValidationErrors(ModelState) }));
                }
                //

                Node node = new Node(Node);
                db.Nodes.Add(node);
                node.Links = new List <Link>();
                db.SaveChanges();
                Link Link = null;
                //create a link if needed.
                if (Node.ParentNodeID != null)
                {
                    CreateLink l = new CreateLink
                    {
                        OriginID = (int)Node.ParentNodeID,
                        TargetID = node.NodeID,
                        Type     = "Parent"
                    };
                    Link = new Link(l);
                    db.Links.Add(Link);
                    db.SaveChanges();
                }


                if (Node.SiblingNodeID != null)
                {
                    CreateLink l = new CreateLink
                    {
                        OriginID = (int)Node.ParentNodeID,
                        TargetID = node.NodeID,
                        Type     = "Sibling"
                    };
                    Link = new Link(l);
                    db.Links.Add(Link);
                    //node.Links.Add(l);
                    db.SaveChanges();
                }

                //link to the layer.
                var layerLink = new LayerLink(new CreateLayerLink {
                    NodeID = node.NodeID, LayerID = Node.LayerID
                });
                db.LayerLinks.Add(layerLink);
                db.SaveChanges();
                return(Json(new { node = node, layerlink = new JsonLayerLink(layerLink), link = Link }));
            }

            return(Json(new { error = Generic.GetValidationErrors(ModelState) }));
        }
Beispiel #4
0
 public IActionResult Webhook(int appId, [FromForm] PodioWebhook hook,
                              [FromServices] VerifyWebhookCommand verifyCommand,
                              [FromServices] CreateLink createLinkCommand,
                              [FromServices] UpdateLink updateLinkCommand)
 {
     lock (PodioLock.Lock)
     {
         _syncService.HandlePodioHook(appId, hook, verifyCommand, createLinkCommand, updateLinkCommand).GetAwaiter().GetResult();
         return(Ok());
     }
 }
        public async Task <IActionResult> CreateLink([FromBody] PodioSyncItemViewModel model,
                                                     [FromServices] CreateLink createLinkCommand,
                                                     [FromServices] CreateSyncEvent createSyncEventCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var podio = new Podio(_options.PodioOptions.ClientId, _options.PodioOptions.ClientSecret);
            var app   = _queryDb.PodioApps.SingleOrDefault(x => x.PodioAppId == model.PodioAppId);
            await podio.AuthenticateWithApp(model.PodioAppId, app.AppToken);

            var podioItem = await podio.ItemService.GetItemByAppItemId(model.PodioAppId, model.AppItemId);

            if (_queryDb.Links.Any(x => x.PodioId == podioItem.ItemId))
            {
                return(Ok(new { ok = false }));
            }
            VssConnection connection             = new VssConnection(new Uri(_options.AzureOptions.ProjectUrl), new VssBasicCredential(string.Empty, _options.AzureOptions.AccessToken));;
            WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>();
            var azureItem = await witClient.GetWorkItemAsync(model.AzureItemId);

            var link = new PodioAzureItemLink
            {
                AzureId       = azureItem.Id.Value,
                AzureUrl      = azureItem.Url,
                AzureRevision = azureItem.Rev.Value,
                PodioAppId    = app.Id,
                PodioUrl      = podioItem.Link,
                PodioRevision = podioItem.CurrentRevision.Revision,
                PodioId       = podioItem.ItemId
            };

            createLinkCommand.InputModel = link;
            createLinkCommand.Run();

            createSyncEventCommand.InputModel = new SyncEvent
            {
                AzureRevision        = link.AzureRevision,
                Initiator            = Initiator.Manuel,
                PodioAzureItemLinkId = link.Id,
                PodioRevision        = link.PodioRevision,
                SyncDate             = DateTime.UtcNow
            };
            createSyncEventCommand.Run();
            return(Ok(new { ok = true }));
        }
Beispiel #6
0
        public IActionResult Create([FromBody] CreateLink command)
        {
            if (!(command.Link.IsValidHttpLink() || command.Link.IsValidHttpsLink()))
            {
                return(BadRequest());
            }

            Link linkInformation = new Link {
                OriginalLink = command.Link, Visitors = 0
            };

            _repository.Add(linkInformation);

            linkInformation.Hash = _hashAlgorithm.Hash(linkInformation.Id);
            _repository.Update(linkInformation);

            return(Ok(new { message = "Created" }));
        }
        public async Task <IActionResult> SyncPodioItem([FromBody] PodioSyncItemViewModel model, [FromServices] CreateLink createLinkCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var podio = new Podio(_options.PodioOptions.ClientId, _options.PodioOptions.ClientSecret);
            var app   = _queryDb.PodioApps.SingleOrDefault(x => x.PodioAppId == model.PodioAppId);
            await podio.AuthenticateWithApp(model.PodioAppId, app.AppToken);

            var item = await podio.ItemService.GetItemByAppItemId(model.PodioAppId, model.AppItemId);

            if (_queryDb.Links.Any(x => x.PodioId == item.ItemId))
            {
                return(Ok(new { ok = false }));
            }
            var azureLink = await _syncService.SyncPodioItemToAzure(createLinkCommand, podio, app, item);

            return(Ok(new { url = azureLink, ok = true }));
        }