コード例 #1
0
        public string checkParentalControlLevel(string movieId, string parentalControlLevelPreference)
        {
            #region Calling external Web API

            // -------------------------------------------------
            // --- Calling / consuming from external Service ---
            // -------------------------------------------------

            /*
             * HttpClient client = new HttpClient();
             * client.BaseAddress = new Uri("http://localhost:1234/");
             * client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             * HttpResponseMessage response = client.GetAsync("api/MovieService/ParentalControlLevel/" + movieId).Result;
             *
             * if (response.IsSuccessStatusCode)
             * {
             *  var data = response.Content.ReadAsAsync<IEnumerable<string>>().Result;
             *  foreach (var x in data)
             *  {
             *      // Process Data
             *  }
             * }
             * else
             * {
             *  Exception ex = new Exception(response.RequestMessage.ToString());
             *  return ex.ToString();
             * }
             */

            #endregion Calling external Web API

            #region Calling internal Web API

            // -------------------------------------------
            // --- Calling Another Service from within ---
            // -------------------------------------------
            var moviesController = new MovieServiceController
            {
                Request = new HttpRequestMessage(HttpMethod.Get, Request.RequestUri.AbsoluteUri.Replace("/ParentalControlService/ParentalControlLevel/", "/MovieService/ParentalControlLevel/"))
            };
            moviesController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = new HttpConfiguration();

            string result = moviesController.getParentalControlLevel(movieId);

            if (result.IndexOf("Exception") > 0)
            {
                Exception ex = new Exception(result);
                return(ex.ToString());
            }

            return((parentalControlLevelPreference == result).ToString());

            #endregion Calling internal Web API
        }
コード例 #2
0
        public ActionResult CheckParentalControlLevel(string parentalControlLevel, string movieId)
        {
            var moviesController = new MovieServiceController
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "/ParentalControlService/ParentalControlLevel/")
            };

            moviesController.Request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = new System.Web.Http.HttpConfiguration();

            string result = moviesController.getParentalControlLevel(movieId);

            if (result.IndexOf("Exception") > 0)
            {
                Exception ex = new Exception(result);
                ViewBag.StatusMessage = ex.ToString();
            }

            ViewBag.StatusMessage = (parentalControlLevel == result) ? "True : Parental Control Level passed"
                                                                     : "False : Parental Control Level failed";

            return(RedirectToAction(nameof(ParentalControlResults), "Home", new { message = ViewBag.StatusMessage }));
        }