private async Task SaveCredentials(LoginRequest data, int workflowId, int connectorId)
        {
            using (var da = new CredentialDataAccess(_conStr))
            {
                var existingCred = (await da.GetByParent <Workflow, Connector>(workflowId, connectorId)).FirstOrDefault();

                if (existingCred != null)
                {
                    existingCred.UserName    = data.Username;
                    existingCred.Password    = data.Password;
                    existingCred.SecretToken = data.SecurityToken;

                    await da.UpdateAsync(existingCred);
                }
                else
                {
                    var cred = new Credential
                    {
                        UserName     = data.Username,
                        Password     = data.Password,
                        SecretToken  = data.SecurityToken,
                        HostUrl      = data.ServerHost,
                        OrgId        = data.OrgId,
                        EndPointName = data.EndpointName,
                        WorkflowId   = workflowId,
                        ConnectorId  = connectorId
                    };

                    await da.CreateAsync(cred);
                }
            }
        }
Beispiel #2
0
        public static async Task <IActionResult> CredentialsUpdate(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "workflows/{workflowId}/{connectorId}/{credentials}/{id}")] HttpRequest req,
            int workflowId, int connectorId)
        {
            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject <Credential>(requestBody);

            data.ConnectorId = connectorId;
            data.WorkflowId  = workflowId;

            using (var da = new CredentialDataAccess(conStr))
            {
                return(new OkObjectResult(await da.UpdateAsync(data)));
            }
        }