ConstructorIO.ConstructorIOAPI.AddAsync C# (CSharp) Method

AddAsync() public method

Adds an Item to your autocomplete.
public AddAsync ( ListItem Item ) : Task
Item ListItem The item to add
return Task
        public async Task<bool> AddAsync(ListItem Item)
        {
            string requestMethod = "POST";
            var addRequest = new ConstructorIORequest(APIRequestType.V1_Item, requestMethod);

            Item.GetAsHash().ToList().ForEach((kvp) => addRequest.RequestBody.Add(kvp.Key, kvp.Value));

            var addResponse = await Requestor.MakeRequest(addRequest);
            return addResponse.Item1;
        }

Usage Example

        private async void btnProcess_Click(object sender, EventArgs e)
        {
            pictureBoxLoading.Visible = true;

            try
            {
                bool bResult = false;

                m_constructorClient = new ConstructorIOAPI(txtAPI.Text, txtKey.Text);
                ListItem createdItem = GetListItem();

                switch (m_sActionValue)
                {
                    case "Add":
                        bResult = await m_constructorClient.AddAsync(createdItem);
                        break;
                    case "Modify ( name of item )":
                        bResult = await m_constructorClient.ModifyAsync(createdItem);
                        break;
                    case "Delete":
                        bResult = await m_constructorClient.RemoveAsync(createdItem);
                        break;
                }

                if(bResult)
                {
                    MessageBox.Show("Success.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            pictureBoxLoading.Visible = false;
        }