Exemple #1
0
        public ActionResult CountOfAvailableType()
        {
            string             cookieValue = string.Empty;
            IEnumerable <Room> r           = null;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseAddress);

                /*if (Request.Cookies["access_token"] != null)
                 * {
                 *  cookieValue = Request.Cookies["access_token"].Value;
                 * }*/

                //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", cookieValue);

                var responseTask = client.GetAsync("Room/Available/GetTypeCount");
                responseTask.Wait();

                var result = responseTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <IList <Room> >();
                    readTask.Wait();
                    r = readTask.Result;
                }
                else
                {
                    r = Enumerable.Empty <Room>();
                    ModelState.AddModelError(string.Empty, "Server error try after some time.");
                }
            }

            RoomRepo rep     = new RoomRepo();
            var      counter = rep.GetCountOfType(r);

            ViewBag.dict = counter;
            return(View());
        }