Exemple #1
0
        private void buttonSelectNumber_Click(object sender, EventArgs e)
        {
            if (listViewNumbersSearch.SelectedItems != null && listViewNumbersSearch.SelectedItems.Count > 0)
            {
                SelectedNumber = listViewNumbersSearch.SelectedItems[0].Text;

                string url = ApiClient.GetNumberReserveUrl();

                HttpRestClient client = new HttpRestClient();

                NumberReserveRequest request = ApiClient.BuildNumberResesrveRequest(listViewNumbersSearch.SelectedItems[0].Text, _lastSearchedAreaCode);

                HttpResponse <List <NumberReserveResponse> > response = client.Post <List <NumberReserveResponse>, NumberReserveRequest>(url, request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    UseWaitCursor = false;

                    if (response.Body != null & response.Body.Count > 0)
                    {
                        foreach (NumberReserveResponse r in response.Body)
                        {
                            listViewNumbersSearch.Items.Add(r.PhoneNumber);
                        }

                        labelValidation.Visible = true;
                    }
                    else
                    {
                        labelValidation.Visible = true;
                    }
                }
                else
                {
                    UseWaitCursor = false;

                    labelValidation.Visible = true;

                    using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(response.ErrorMessage)))
                    {
                        stream.Position = 0;
                        DataContractJsonSerializer serizlizer = new DataContractJsonSerializer(typeof(ErrorResponse));
                        ErrorResponse errorResponse           = serizlizer.ReadObject(stream) as ErrorResponse;
                        labelValidation.Text = errorResponse.Message;
                    }
                }

                Close();
            }
            else
            {
                labelValidation.Text = "No number selected";
            }
        }
Exemple #2
0
        public static NumberReserveRequest BuildNumberResesrveRequest(string number, string areaCode)
        {
            var request = new NumberReserveRequest
            {
                CustomerId  = clientId,
                RequestId   = GetRequestId(),
                PhoneNumber = number,
                AreaCode    = areaCode
            };

            request.Hash = string.Format("{0}{1}{2}{3}{4}", clientId, number, areaCode, request.RequestId, secret);

            return(request);
        }