Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(int Id)
        {
            var                 stajyer = new StajyerData();
            HttpClient          client  = _api.initial();
            HttpResponseMessage res     = await client.DeleteAsync($"api/stajyers/{Id}");

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Details(int Id)
        {
            var                 stajogr = new StajyerData();
            HttpClient          client  = _api.initial();
            HttpResponseMessage res     = await client.GetAsync($"api/stajyers/{Id}");

            if (res.IsSuccessStatusCode)
            {
                var results = res.Content.ReadAsStringAsync().Result;
                stajogr = JsonConvert.DeserializeObject <StajyerData>(results);
            }
            return(View(stajogr));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int Id)
        {
            StajyerData stajyer = new StajyerData();

            using (HttpClient httpClient = _api.initial())
            {
                using (var response = await httpClient.GetAsync("api/stajyers/" + Id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    stajyer = JsonConvert.DeserializeObject <StajyerData>(apiResponse);
                }
            }
            return(View(stajyer));
        }
Ejemplo n.º 4
0
        public IActionResult Create(StajyerData stajyer)
        {
            HttpClient client = _api.initial();

            //Http Post
            var postTask = client.PostAsJsonAsync <StajyerData>("api/stajyers", stajyer);

            postTask.Wait();
            var result = postTask.Result;

            if (result.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Ejemplo n.º 5
0
        public IActionResult Edit(StajyerData stajyer)
        {
            using (HttpClient httpClient = _api.initial())
            {
                httpClient.BaseAddress = new Uri("https://localhost:44327/api/stajyers");

                //HTTP POST
                var putTask = httpClient.PutAsJsonAsync <StajyerData>("stajyers", stajyer);
                putTask.Wait();

                var result = putTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(stajyer));
        }