Пример #1
0
        public void ViewAttractionById()
        {
            Console.Write("Enter Attraction ID: ");
            int userInput = int.Parse(Console.ReadLine());

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token);
            var readTask = _client.GetAsync("https://localhost:44322/api/Attraction/");
            var response = readTask.Result;

            if (response.IsSuccessStatusCode)
            {
                Console.Clear();
                AttractionListItems attraction = _client.GetAsync($"https://localhost:44322/api/Attraction/{userInput}").Result.Content.ReadAsAsync <AttractionListItems>().Result;
                if (attraction != null)
                {
                    Console.WriteLine($"Attraction ID: {attraction.AttId}\n" +
                                      $"Zoo ID {attraction.ZooId}" +
                                      $"Animals: {attraction.Animals}\n" +
                                      $"Experiences: {attraction.Experiences}\n" +
                                      $"Seasonal Attractions: {attraction.SeasonalAttractions}\n" +
                                      $"Aquarium: {attraction.HasAquaticExhibit}\n" +
                                      $"Garden: {attraction.HasGarden}\n");
                }
                Console.ReadLine();
            }
        }
Пример #2
0
        public void UpdateAttraction()
        {
            Console.Clear();
            Console.Write("Enter the Zoo ID for the Zoo You'd like to update: ");
            int id = int.Parse(Console.ReadLine());

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token);
            var getTask  = _client.GetAsync("https://localhost:44322/api/Attraction/");
            var response = getTask.Result;
            AttractionListItems oldAttraction = new AttractionListItems();

            if (response.IsSuccessStatusCode)
            {
                Console.Clear();
                oldAttraction = _client.GetAsync("https://localhost:44322/api/Atraction/{id}").Result.Content.ReadAsAsync <AttractionListItems>().Result;
                if (oldAttraction != null)
                {
                    Console.WriteLine($"Attraction ID: {oldAttraction.AttId}\n" +
                                      $"Zoo ID {oldAttraction.ZooId}" +
                                      $"Animals: {oldAttraction.Animals}\n" +
                                      $"Experiences: {oldAttraction.Experiences}\n" +
                                      $"Seasonal Attractions: {oldAttraction.SeasonalAttractions}\n" +
                                      $"Aquarium: {oldAttraction.HasAquaticExhibit}\n" +
                                      $"Garden: {oldAttraction.HasGarden}\n");
                }
                else
                {
                    Console.WriteLine("The animals must have been hungry and ate that ID, please enter a valid Zoo ID.");
                }
            }
            Dictionary <string, string> newAttraction = new Dictionary <string, string>();

            //Console.Write("Zoo ID: ");
            //string zooId = Console.ReadLine(); // Need to figure out how to make it automatically use the key  method for ZooId
            //newZoo.Add("ZooId", zooId);

            Console.Write("Zoo ID: ");
            int zooId = int.Parse(Console.ReadLine());

            newAttraction.Add("ZooId", zooId.ToString());

            Console.Write("Animals: ");
            string animals = Console.ReadLine();

            newAttraction.Add("Animals", animals);

            Console.Write("Experiences: ");
            string experiences = Console.ReadLine();

            newAttraction.Add("Location", experiences);

            Console.Write("Seasonal Attractions: ");
            string seasonalAttractions = Console.ReadLine();

            newAttraction.Add("Seasonal Attractions", seasonalAttractions);

            Console.Write("Aquarium: ");
            bool aquarium = bool.Parse(Console.ReadLine());

            newAttraction.Add("Aquarium", aquarium.ToString());

            Console.Write("Garden: ");
            bool garden = bool.Parse(Console.ReadLine());

            newAttraction.Add("Garden", garden.ToString());

            HttpContent newAttractionHTTP = new FormUrlEncodedContent(newAttraction);

            var putResponse = _client.PostAsync("https://localhost:44322/api/Attraction/", newAttractionHTTP);

            if (putResponse.Result.IsSuccessStatusCode)
            {
                Console.WriteLine("Attraction Successfully Create");
            }
            else
            {
                Console.WriteLine("Failed to create Attraction.");
            }
            Console.ReadKey();
        }