예제 #1
0
        public ActionResult Create(Vinyl vinyl)
        {
            CreateViewModel model = new CreateViewModel();
            model.Vinyl = vinyl ?? new Vinyl();

            HttpResponseMessage artistResponse = ArtistsGateway.ReadAll();
            if (!artistResponse.IsSuccessStatusCode)
                return new HttpStatusCodeResult(artistResponse.StatusCode);
            model.Artists = artistResponse.Content.ReadAsAsync<IEnumerable<Artist>>().Result;

            HttpResponseMessage genreResponse = GenresGateway.ReadAll();
            if (!genreResponse.IsSuccessStatusCode)
                return new HttpStatusCodeResult(genreResponse.StatusCode);
            model.Genres = genreResponse.Content.ReadAsAsync<IEnumerable<Genre>>().Result;

            return View(model);
        }
예제 #2
0
        public void Setup()
        {
            // Get the base address value from App.config.
            string baseAddress = ConfigurationManager.AppSettings["ApiBaseAddress"];

            // Setup client for calling the api.
            client = new HttpClient();
            client.BaseAddress = new Uri(baseAddress);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json")
            );

            // Instantiate a test vinyl
            testVinyl = new Vinyl()
            {
                Id = 0,
                Name = "Test",
                Price = 100,
                Year = 1999
            };
            HttpResponseMessage response = client.PostAsJsonAsync("api/vinyls/", testVinyl).Result;
            testVinyl = response.Content.ReadAsAsync<Vinyl>().Result;
        }