Exemplo n.º 1
0
        public async Task <IActionResult> UpdateGroup(int id)
        {
            Group group = new Group();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://localhost:5001/api/Group/GetGroup/" + id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    group = JsonConvert.DeserializeObject <Group>(apiResponse);
                }
            }
            return(View(group));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddGroup(Group group)
        {
            Group receivedGroup = new Group();

            using (var httpClient = new HttpClient())
            {
                StringContent content = new StringContent(JsonConvert.SerializeObject(group), Encoding.UTF8, "application/json");
                using (var response = await httpClient.PostAsync("https://localhost:5001/api/Group/PostGroup", content))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    receivedGroup = JsonConvert.DeserializeObject <Group>(apiResponse);
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateGroup(Group group)
        {
            using (var httpClient = new HttpClient())
            {
                string serailizedProduct = JsonConvert.SerializeObject(group);

                var inputMessage = new HttpRequestMessage
                {
                    Content = new StringContent(serailizedProduct, Encoding.UTF8, "application/json")
                };

                inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage message = httpClient.PutAsync("https://localhost:5001/api/Group/PutGroup", inputMessage.Content).Result;

                if (!message.IsSuccessStatusCode)
                {
                    throw new ArgumentException(message.ToString());
                }

                return(RedirectToAction("Index"));
            }
        }