Пример #1
0
        /// <summary>
        /// Method requests the Server with the URL and returns the persons file
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <StarWarsPeople> HttpGetCurrentPeople(string url)
        {
            string result = null;

            using (HttpClient syncClient = new HttpClient())
            {
                var response = await syncClient.GetAsync(url);

                result = await response.Content.ReadAsStringAsync();
            }

            StarWarsPeople starWarsPeople = JsonConvert.DeserializeObject <StarWarsPeople>(result);

            return(starWarsPeople);
        }
Пример #2
0
        public async Task DisplayPeopleFile()
        {
            //Task<StarWarsPeople> starWarsPeople = GetJsonFiles.GetPeopleFile();

            StarWarsPeople starWarsPeople = await GetJsonFiles.GetPeopleFile();

            List <StarWarsPeople> starWarsPeoples = new List <StarWarsPeople>();

            starWarsPeoples.Add(starWarsPeople);

            dataGridView_swDB.DataSource = new BindingList <StarWarsPeople>(starWarsPeoples);

            var bindingList = new BindingList <StarWarsPeople>(starWarsPeoples);
            var source      = new BindingSource(bindingList, null);
        }
Пример #3
0
        /// <summary>
        /// Method requests API to get a person
        /// </summary>
        /// <returns></returns>
        public static async Task <StarWarsPeople> GetPeopleFile()
        {
            string url;

            StringBuilder sb = new StringBuilder();

            sb.Clear();
            sb.Append("https://swapi.co/api/people/1/?format=json");

            url = sb.ToString();

            StarWarsPeople starWarsPeople = new StarWarsPeople();

            Task <StarWarsPeople> getSWPeople = HttpGetCurrentPeople(url);

            getSWPeople.Wait();

            starWarsPeople = await getSWPeople;

            return(starWarsPeople);
        }
Пример #4
0
        private void moreInfo_btn_Click(object sender, EventArgs e)
        {
            if (dataGridView_swDB.SelectedRows.Count == 1)
            {
                if (dataGridView_swDB.GetType() == typeof(StarWarsPeople))
                {
                    StarWarsPeople swPeople = new StarWarsPeople();
                    swPeople = (StarWarsPeople)dataGridView_swDB.CurrentRow.DataBoundItem;

                    DetailFormPlanets detailFormPeople = new DetailFormPlanets(swPeople);
                    detailFormPeople.ShowDialog();
                }
                else if (dataGridView_swDB.GetType() == typeof(StarWarsPlanets))
                {
                    StarWarsPlanets swPlanets = new StarWarsPlanets();
                    swPlanets = (StarWarsPlanets)dataGridView_swDB.CurrentRow.DataBoundItem;

                    DetailFormPlanets detailFormPlanets = new DetailFormPlanets(swPlanets);
                    detailFormPlanets.ShowDialog();
                }
            }
        }
 public DetailFormPlanets(StarWarsPeople swPeople)
 {
     InitializeComponent();
     _swPeople = swPeople;
 }