Пример #1
0
            void Execute()
            {
                RestClient client = new RestClient();

                client.BaseUrl = new Uri("https://gogotaxi.com.ua");


                RestRequest request = new RestRequest(Method.GET);

                request.Resource = "/api/driver/me";

                //request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                request.AddHeader("token", "ce18c8257503ba0dfa0656ea4306d22b3933ffbe1923aaff18ecc078b5070a52");


                IRestResponse response = client.Execute(request);
                string        content  = response.Content;

                object desContent1 = JsonConvert.DeserializeObject(content);

                Response2 desContent = JsonConvert.DeserializeObject <Response2>(content);

                Console.Write(desContent1);
                Console.ReadKey();
            }
Пример #2
0
        public ActionResult Draw()
        {
            string DeckIdCookie = Request.Cookies["DeckIdCookie"].Value;

            ViewBag.bob = DeckIdCookie;

            var input = Request.Cookies["Link"] != null ? Request.Cookies["Link"].Value : String.Empty;

            HttpWebRequest WR2 = WebRequest.CreateHttp($"{input}");

            WR2.UserAgent = ".NET Framework Test Client";

            HttpWebResponse Response2;

            try
            {
                Response2 = (HttpWebResponse)WR2.GetResponse();
            }
            catch (WebException ex)
            {
                ViewBag.Error2            = "Exception";
                ViewBag.ErrorDescription2 = ex.Message;
                return(View("Index"));
            }

            if (Response2.StatusCode != HttpStatusCode.OK)
            {
                ViewBag.Error2            = Response2.StatusCode;
                ViewBag.ErrorDescription2 = Response2.StatusDescription;
                return(View("Index"));
            }

            StreamReader reader2   = new StreamReader(Response2.GetResponseStream());
            string       Card2Data = reader2.ReadToEnd();

            try
            {
                JObject Json2Data = JObject.Parse(Card2Data);
                ViewBag.Cards = /*(JObject)*/ Json2Data["cards"];
            }
            catch (Exception ex)
            {
                ViewBag.Error2            = "JSON Issue";
                ViewBag.ErrorDescription2 = ex.Message;
                return(View("Index"));
            }

            return(View("Index"));
        }
Пример #3
0
        public async static Task <Response2> SaveChanges(LocalDatacontext db)
        {
            try
            {
                await db.SaveChangesAsync();

                return(new Response2 {
                    IsSuccess = true,
                });
            }
            catch (Exception ex)
            {
                var response = new Response2 {
                    IsSuccess = false,
                };

                if (ex.InnerException != null &&

                    ex.InnerException.InnerException != null &&

                    ex.InnerException.InnerException.Message.Contains("_Index"))

                {
                    response.Message = "There is a record with the same value";
                }

                else if (ex.InnerException != null &&

                         ex.InnerException.InnerException != null &&

                         ex.InnerException.InnerException.Message.Contains("REFERENCE"))

                {
                    response.Message = "The record can't be delete because it has related records";
                }

                else
                {
                    response.Message = ex.Message;
                }
                return(response);
            }
        }
Пример #4
0
        public ActionResult Details(string id)
        {
            HttpWebRequest WR = WebRequest.CreateHttp($"https://api.yelp.com/v3/businesses/{id}");

            WR.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0";
            string key = ConfigurationManager.AppSettings["AuthKey"];

            WR.Headers.Add("Authorization", key);
            HttpWebResponse Response;

            try
            {
                Response = (HttpWebResponse)WR.GetResponse();
            }
            catch (WebException e)
            {
                ViewBag.Error            = "Bad API Response";
                ViewBag.ErrorDescription = e.Message;
                return(View("Error"));
            }

            if (Response.StatusCode != HttpStatusCode.OK)
            {
                ViewBag.Error            = Response.StatusCode;
                ViewBag.ErrorDescription = Response.StatusDescription;
                return(View("Error"));
            }

            StreamReader reader = new StreamReader(Response.GetResponseStream());
            string       Data   = reader.ReadToEnd();

            try
            {
                JObject JsonData = JObject.Parse(Data);
                ViewBag.Data = JsonData;
            }
            catch (Exception e)
            {
                ViewBag.Error            = "JSON Issue";
                ViewBag.ErrorDescription = e.Message;
                return(View("Error"));
            }

            //Calculate Wall Score Logic
            ThinWallsEntities db = new ThinWallsEntities(); //pulls info from db

            List <Review> reviews = (from r in db.Reviews
                                     where r.YelpID == id
                                     select r).ToList(); //pulls only item w/ matching yelpid

            ViewBag.Reviews = reviews;
            int average = 0;

            foreach (var r in reviews)
            {
                average += r.WallScore;
            }
            if (average == 0)
            {
                ViewBag.Score = average;
            }
            else
            {
                average       = average / reviews.Count; //calculates average of all the scores
                ViewBag.Score = average;                 //so view can access the info
            }

            HttpWebRequest WR2 = WebRequest.CreateHttp($"https://api.yelp.com/v3/businesses/{id}/reviews");

            WR2.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0";
            //string key2 = ConfigurationManager.AppSettings["AuthKey"];
            WR2.Headers.Add("Authorization", key);
            HttpWebResponse Response2;

            try
            {
                Response2 = (HttpWebResponse)WR2.GetResponse();
            }
            catch (WebException e)
            {
                ViewBag.Error            = "Bad API Response";
                ViewBag.ErrorDescription = e.Message;
                return(View("Error"));
            }

            if (Response.StatusCode != HttpStatusCode.OK)
            {
                ViewBag.Error            = Response2.StatusCode;
                ViewBag.ErrorDescription = Response2.StatusDescription;
                return(View("Error"));
            }

            StreamReader reader2     = new StreamReader(Response2.GetResponseStream());
            string       yelpReviews = reader2.ReadToEnd();

            try
            {
                JObject JsonData2 = JObject.Parse(yelpReviews);
                ViewBag.YelpReviews = JsonData2["reviews"];
            }
            catch (Exception e)
            {
                ViewBag.Error            = "JSON Issue";
                ViewBag.ErrorDescription = e.Message;
                return(View("Error"));
            }

            return(View());
        }
Пример #5
0
        public ActionResult Shuffle()
        {
            string DeckIdCookie = Request.Cookies["DeckIdCookie"].Value;
            //use an if statement to discard of web request post using

            HttpWebRequest WR4 = WebRequest.CreateHttp($"https://deckofcardsapi.com/api/deck/{DeckIdCookie}/shuffle/");

            WR4.UserAgent = ".NET Framework Test Client";

            HttpWebResponse Response4;

            try
            {
                Response4 = (HttpWebResponse)WR4.GetResponse();
            }
            catch (WebException ex2)
            {
                ViewBag.Error            = "Exception stage 1";
                ViewBag.ErrorDescription = ex2.Message + $"<br />https://deckofcardsapi.com/api/deck/{DeckIdCookie}/shuffle/";
                return(View("Index"));
            }

            if (Response4.StatusCode != HttpStatusCode.OK)
            {
                ViewBag.Error            = Response4.StatusCode;
                ViewBag.ErrorDescription = Response4.StatusDescription;
                return(View("Index"));
            }

            StreamReader reader4   = new StreamReader(Response4.GetResponseStream());
            string       Card4Data = reader4.ReadToEnd();

            try
            {
                var input = Request.Cookies["Link"] != null ? Request.Cookies["Link"].Value : String.Empty;

                HttpWebRequest WR2 = WebRequest.CreateHttp($"{input}");
                WR2.UserAgent = ".NET Framework Test Client";

                HttpWebResponse Response2;

                try
                {
                    Response2 = (HttpWebResponse)WR2.GetResponse();
                }
                catch (WebException ex)
                {
                    ViewBag.Error            = "Exception stage 2";
                    ViewBag.ErrorDescription = ex.Message;
                    return(View("Index"));
                }

                if (Response2.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Error            = Response2.StatusCode;
                    ViewBag.ErrorDescription = Response2.StatusDescription;
                    return(View("Index"));
                }

                StreamReader reader2   = new StreamReader(Response2.GetResponseStream());
                string       Card2Data = reader2.ReadToEnd();

                try
                {
                    JObject Json2Data = JObject.Parse(Card2Data);
                    ViewBag.Cards = /*(JObject)*/ Json2Data["cards"];
                }
                catch (Exception ex)
                {
                    ViewBag.Error            = "JSON Issue";
                    ViewBag.ErrorDescription = ex.Message;
                    return(View("Index"));
                }
            }
            catch (Exception ex2)
            {
                ViewBag.Error            = "JSON Issue 2";
                ViewBag.ErrorDescription = ex2.Message;
                return(View("Index"));
            }

            return(View("Index"));
        }
Пример #6
0
        public ActionResult Index()
        {
            HttpWebRequest WR = WebRequest.CreateHttp("https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1");

            WR.UserAgent = ".NET Framework Test Client";

            HttpWebResponse Response3;

            try
            {
                Response3 = (HttpWebResponse)WR.GetResponse();
            }
            catch (WebException e)
            {
                ViewBag.Error            = "Exception";
                ViewBag.ErrorDescription = e.Message;
                return(View());
            }

            if (Response3.StatusCode != HttpStatusCode.OK)
            {
                ViewBag.Error            = Response3.StatusCode;
                ViewBag.ErrorDescription = Response3.StatusDescription;
                return(View());
            }

            StreamReader reader   = new StreamReader(Response3.GetResponseStream());
            string       CardData = reader.ReadToEnd();

            try
            {
                JObject JsonData = JObject.Parse(CardData);
                ViewBag.DeckId = JsonData["deck_id"];
                ViewBag.Remain = JsonData["remaining"];
                //Session["x"] = ViewBag.DeckId;
                //string sess = (string)Session["x"];
                //id = (string)JsonData["deck_id"];

                //var domain = "https://deckofcardsapi.com/api/deck/";
                //string id = ViewBag.DeckId;
                //var end = "/draw /? count = 5";
                //string full = $"{domain}{id}{end}";
                //$"{domain}{ViewBag.DeckId}{end}"

                //HttpCookie myCookie = new HttpCookie("url");
                id  = ViewBag.DeckId;
                url = $"https://deckofcardsapi.com/api/deck/{ViewBag.DeckId}/draw/?count=5";
                Response.Cookies["Link"].Value           = url;
                Response.Cookies["DeckIdCookie"].Value   = ViewBag.DeckId;
                Response.Cookies["Link"].Expires         = DateTime.Now.AddMinutes(2);
                Response.Cookies["DeckIdCookie"].Expires = DateTime.Now.AddMinutes(2);

                //myCookie.Expires = DateTime.Now.AddHours(12);
                //HttpResponse.AppendCookie(myCookie);

                var input = Request.Cookies["Link"] != null ? Request.Cookies["Link"].Value : String.Empty;

                //if for some reason it starts throwing null exception reference again, just paste in url above and replace input and it will work again
                HttpWebRequest WR2 = WebRequest.CreateHttp($"{input}");
                WR2.UserAgent = ".NET Framework Test Client";

                HttpWebResponse Response2;

                try
                {
                    Response2 = (HttpWebResponse)WR2.GetResponse();
                }
                catch (WebException ex)
                {
                    ViewBag.Error2            = "Exception";
                    ViewBag.ErrorDescription2 = ex.Message;
                    return(View());
                }

                if (Response2.StatusCode != HttpStatusCode.OK)
                {
                    ViewBag.Error2            = Response2.StatusCode;
                    ViewBag.ErrorDescription2 = Response2.StatusDescription;
                    return(View());
                }

                StreamReader reader2   = new StreamReader(Response2.GetResponseStream());
                string       Card2Data = reader2.ReadToEnd();

                try
                {
                    JObject Json2Data = JObject.Parse(Card2Data);
                    ViewBag.Cards = /*(JObject)*/ Json2Data["cards"];

                    //ViewBag.Cards1 = (JObject)Json2Data["cards"][0];
                    //ViewBag.Cards2 = (JObject)Json2Data["cards"][1];
                    //ViewBag.Cards3 = (JObject)Json2Data["cards"][2];
                    //ViewBag.Cards4 = (JObject)Json2Data["cards"][3];
                    //ViewBag.Cards5 = (JObject)Json2Data["cards"][4];

                    //ViewBag.Images1 = JsonData["cards"][0]["image"];
                    //ViewBag.Images2 = JsonData["cards"][1]["image"];
                    //ViewBag.Images3 = JsonData["cards"][2]["image"];
                    //ViewBag.Images4 = JsonData["cards"][3]["image"];
                    //ViewBag.Images5 = JsonData["cards"][4]["image"];

                    //ViewBag.Value1 = JsonData["cards"][0]["value"];
                    //ViewBag.Value2 = JsonData["cards"][1]["value"];
                    //ViewBag.Value3 = JsonData["cards"][2]["value"];
                    //ViewBag.Value4 = JsonData["cards"][3]["value"];
                    //ViewBag.Value5 = JsonData["cards"][4]["value"];

                    //ViewBag.Suit1 = JsonData["cards"][0]["suit"];
                    //ViewBag.Suit2 = JsonData["cards"][1]["suit"];
                    //ViewBag.Suit3 = JsonData["cards"][2]["suit"];
                    //ViewBag.Suit4 = JsonData["cards"][3]["suit"];
                    //ViewBag.Suit5 = JsonData["cards"][4]["suit"];
                }
                catch (Exception ex)
                {
                    ViewBag.Error2            = "JSON Issue";
                    ViewBag.ErrorDescription2 = ex.Message;
                    return(View());
                }
            }
            catch (Exception e)
            {
                ViewBag.Error            = "JSON Issue";
                ViewBag.ErrorDescription = e.Message;
                return(View());
            }

            return(View());
        }
Пример #7
0
 private static void Log(Response2 r1)
 {
     Console.WriteLine($"({r1.Text.Id}) - State - {r1.Text.State}");
 }