Пример #1
0
        async Task RunAsync(NotificationDataModel data)
        {
            var myContent     = JsonNet.Serialize(data);
            var stringContent = new StringContent(myContent, UnicodeEncoding.UTF8, "application/json");

            HttpClient client = new HttpClient();

            //client.BaseAddress = new Uri("https://localhost:44333/api/SendPushNotificationPartners/");
            client.BaseAddress = new Uri("https://appi-atah.azurewebsites.net/api/SendPushNotificationPartners/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                var responsevar = "";
                HttpResponseMessage response = await client.PostAsync("https://appi-atah.azurewebsites.net/api/SendPushNotificationPartners/", stringContent);

                //HttpResponseMessage response = await client.PostAsync("https://localhost:44333/api/SendPushNotificationPartners/", stringContent);
                if (response.IsSuccessStatusCode)
                {
                    responsevar = await response.Content.ReadAsStringAsync();
                }
                Respuesta res = JsonNet.Deserialize <Respuesta>(responsevar);

                MessageBox.Show(res.mensaje);
                clean();
            }
            catch (Exception e) {
                string error = e.Message;
                MessageBox.Show("Error con el servicio intente màs tarde");
            }
        }
Пример #2
0
        private async void BtnEnviar_ClickAsync(object sender, EventArgs e)
        {
            List <string>   socios      = new List <string>();
            List <PARTNERS> partners    = new List <PARTNERS>();
            List <PARTNERS> conductores = new List <PARTNERS>();

            if (string.IsNullOrEmpty(tbTitle.Text))
            {
                tbTitle.Focus();
                MessageBox.Show("Falta título de notificación");
                return;
            }
            if (string.IsNullOrEmpty(tbMessage.Text))
            {
                tbMessage.Focus();
                MessageBox.Show("Falta mensaje de notificación");
                return;
            }
            //string notificacion = "\"NOTIFICATION\":{ \"TITLE\":\"" + tbTitle.Text + "\",\"MESSAGE\":\"" + tbMessage.Text + "\"}";
            NOTIFICATION noti = new NOTIFICATION();

            noti.TITLE   = tbTitle.Text;
            noti.MESSAGE = tbMessage.Text;

            PARTNERS p;

            for (int i = 0; i < dataGridView1.RowCount; i++)
            {
                if (Boolean.Parse(dataGridView1.Rows[i].Cells["ENVIAR"].Value.ToString()) == true)
                {
                    p         = new PARTNERS();
                    p.USUARIO = dataGridView1.Rows[i].Cells["USUARIO"].Value.ToString();
                    partners.Add(p);
                    //socios.Add("{\"USUARIO\":\"" + dataGridView1.Rows[i].Cells["USUARIO"].Value.ToString()+ "\"");
                }
            }
            for (int i = 0; i < dataGridView2.RowCount; i++)
            {
                if (Boolean.Parse(dataGridView2.Rows[i].Cells["ENVIARC"].Value.ToString()) == true)
                {
                    p         = new PARTNERS();
                    p.USUARIO = dataGridView2.Rows[i].Cells["CONDUCTOR"].Value.ToString();
                    conductores.Add(p);
                    //socios.Add("{\"USUARIO\":\"" + dataGridView1.Rows[i].Cells["USUARIO"].Value.ToString()+ "\"");
                }
            }

            if (partners.Count == 0)
            {
                partners = null;
            }
            if (conductores.Count == 0)
            {
                conductores = null;
            }

            NotificationDataModel data = new NotificationDataModel();

            data.DRIVERS      = conductores;
            data.PARTNERS     = partners;
            data.NOTIFICATION = noti;
            await RunAsync(data);
        }