Ejemplo n.º 1
0
        public bool Auth(string login, string password)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(API_BASE_URL + @"/auth");

            request.Method      = METHOD_POST;
            request.ContentType = CONTENT_TYPE;

            object authRequest = new { login, password };

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(JsonConvert.SerializeObject(authRequest));
            }

            string res = makeRequest(request);

            if (string.IsNullOrEmpty(res))
            {
                return(false);
            }

            ApiDefaultResponse auth = JsonConvert.DeserializeObject <ApiDefaultResponse>(res);

            if (!string.IsNullOrEmpty(auth.response.ToString()))
            {
                return(auth.response.Equals(true));
            }

            return(false);
        }
Ejemplo n.º 2
0
        public List <NeedsEntity> Find(int client_id, int realtor_id)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(NEEDS_API_URL + @"/get-by-participants");

            request.ContentType = CONTENT_TYPE;
            request.Method      = METHOD_POST;
            List <NeedsEntity> needsEntity = new List <NeedsEntity>();

            object realtorDataRequest = new { client_id, realtor_id };

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(JsonConvert.SerializeObject(realtorDataRequest));
            }

            string res = this.makeRequest(request);

            ApiDefaultResponse defaultResponse = JsonConvert.DeserializeObject <ApiDefaultResponse>(res);

            JArray innerResponse = (JArray)defaultResponse.response;

            JObject[] types = innerResponse.Select(jv => (JObject)jv).ToArray();

            foreach (JObject type in types)
            {
                needsEntity.Add(GetNeedsFromJson(type));
            }
            return(needsEntity);
        }
Ejemplo n.º 3
0
        public void table()
        {
            ApiDefaultResponse apiResponse = _clientApiClient.Get();

            dt = (DataTable)JsonConvert.DeserializeObject(apiResponse.response.ToString(), typeof(DataTable));

            dataGridView1.DataSource = dt;
            try
            {
                dataGridView1.Columns.Remove("id");
            }
            catch (Exception exp)
            {
                MessageBox.Show($@"Что-то пошло не так! Сообщение: {exp.Message}");
            }
        }
Ejemplo n.º 4
0
        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                ApiDefaultResponse apiResponse = _realtiesApiClient.FindByLatLong(float.Parse(x1.Text), float.Parse(у1.Text),
                                                                                  float.Parse(x2.Text), float.Parse(у2.Text));

                dt = (DataTable)JsonConvert.DeserializeObject(apiResponse.response.ToString(), typeof(DataTable));

                dataGridView1.DataSource = dt;

                dataGridView1.Columns.Remove("id");
            }
            catch (Exception exp)
            {
                MessageBox.Show($@"Что-то пошло не так! Сообщение: {exp.Message}");
            }
        }
Ejemplo n.º 5
0
        private void type_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (type.SelectedIndex == 0)
                {
                    return;
                }
                ApiDefaultResponse apiResponse = _realtiesApiClient.GetByType(int.Parse(type.SelectedValue.ToString()));

                dt = (DataTable)JsonConvert.DeserializeObject(apiResponse.response.ToString(), typeof(DataTable));

                dataGridView1.DataSource = dt;

                dataGridView1.Columns.Remove("id");
            }
            catch (Exception exp)
            {
                MessageBox.Show($@"Что-то пошло не так! Сообщение: {exp.Message}");
            }
        }
Ejemplo n.º 6
0
        public List <RealtorEntity> GetRealtors()
        {
            List <RealtorEntity> realtorEntities = new List <RealtorEntity>();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(REALTOR_API_URL + @"/get");

            request.ContentType = CONTENT_TYPE;
            request.Method      = METHOD_GET;

            string             res             = this.makeRequest(request);
            ApiDefaultResponse defaultResponse = JsonConvert.DeserializeObject <ApiDefaultResponse>(res);

            JArray innerResponse = (JArray)defaultResponse.response;

            JObject[] types = innerResponse.Select(jv => (JObject)jv).ToArray();

            foreach (JObject type in types)
            {
                realtorEntities.Add(JsonConvert.DeserializeObject <RealtorEntity>(type.ToString()));
            }

            return(realtorEntities);
        }
Ejemplo n.º 7
0
        public List <DealEntity> GetDeals()
        {
            List <DealEntity> dealsEntity = new List <DealEntity>();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Deals_API_URL + @"/get");

            request.ContentType = CONTENT_TYPE;
            request.Method      = METHOD_GET;

            string             res             = this.makeRequest(request);
            ApiDefaultResponse defaultResponse = JsonConvert.DeserializeObject <ApiDefaultResponse>(res);

            JArray innerResponse = (JArray)defaultResponse.response;

            JObject[] types = innerResponse.Select(jv => (JObject)jv).ToArray();

            foreach (JObject type in types)
            {
                dealsEntity.Add(getDealsFromJson(type));
            }

            return(dealsEntity);
        }
Ejemplo n.º 8
0
        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                ApiDefaultResponse apiResponse = _clientApiClient.Find(name.Text,
                                                                       surname.Text, patronomic.Text);

                dt = (DataTable)JsonConvert.DeserializeObject(apiResponse.response.ToString(), typeof(DataTable));

                dataGridView1.DataSource = dt;
                try
                {
                    dataGridView1.Columns.Remove("id");
                }
                catch (Exception exp)
                {
                    MessageBox.Show($@"Что-то пошло не так! Сообщение: {exp.Message}");
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show($@"Что-то пошло не так! Сообщение: {exp.Message}");
            }
        }