GSMNotificationController.cs 3.68 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Newtonsoft.Json.Linq;
using ControlPanel.Models;
using System.Runtime.Serialization;
using ControlPanel.LogicLayers;
using System.IO;
using System.Web;
using System.Web.Mvc;


namespace ControlPanel.Controllers
{

    public class Region
    {
        public int id;
        public string title;
    }

    public class GSMNotificationController : Controller
    {
         public JObject GetGSMNotifications(int page, int start, int limit)
        {

            List<Region> lstRegion = new List<Region>();

            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://46.226.227.171/importer/regions.php");
            httpWebRequest.ContentType = "text/json";
            httpWebRequest.Method = "POST";

            try
            {
                var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var res = streamReader.ReadToEnd();

                    string str = res.ToString();

      

                    dynamic obj = JObject.Parse(res);

                    try
                    {

                        var lst = obj["data"];

                        foreach (var p in lst)
                        {
                            try
                            {
                                dynamic json = JValue.Parse(p.ToString());

                                int id = json.id;
                                string title= json.title;

                                lstRegion.Add(new Region { id = id, title = title });
                             
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    catch (Exception)
                    {

                    }
                }

            }
            catch (Exception)
            {
             
            }

            JObject result = JObject.FromObject(new
            {
                data = lstRegion
            });
            return result;
        }











         public String GetList(int id)
        {


            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://46.226.227.171/importer/view.php?region=" + id);
            httpWebRequest.ContentType = "text/json";
            httpWebRequest.Method = "POST";

            

            try
            {
                var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), encode))
                {
                    var res = streamReader.ReadToEnd();

                    String str = res.ToString();
                    dynamic obj = JObject.Parse(res);
                

                    /*
                  JObject result = JObject.FromObject(new
                  {
                      info = str
                  });
                     * */

                    return str;
        
                  


              }

            }
            catch (Exception)
            {
             return null;
            }


          
        }




    }














}