Exemplo n.º 1
0
        public async Task <IActionResult> TodoDelete(int Id)
        {
            var                 note     = new NoteModelData();
            HttpClient          client   = noteAPI.Initial();
            HttpResponseMessage response = await client.DeleteAsync($"api/todo/{Id}");

            return(RedirectToAction("Todo"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int Id)
        {
            NoteModelData       notes    = new NoteModelData();
            HttpClient          client   = noteAPI.Initial();
            HttpResponseMessage response = await client.GetAsync($"api/note/{Id}");

            if (response.IsSuccessStatusCode)
            {
                var results = response.Content.ReadAsStringAsync().Result;
                notes = JsonConvert.DeserializeObject <NoteModelData>(results);
            }
            return(View(notes));
        }
Exemplo n.º 3
0
        public IActionResult Create(NoteModelData note)
        {
            HttpClient client = noteAPI.Initial();

            var postTask = client.PostAsJsonAsync <NoteModelData>("api/note", note);

            postTask.Wait();

            var result = postTask.Result;

            if (result.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemplo n.º 4
0
        public IActionResult Edit(NoteModelData note)
        {
            NoteModelData savedNote = new NoteModelData();
            HttpClient    client    = noteAPI.Initial();
            //using (var httpClient = new HttpClient())
            //{
            //httpClient.BaseAddress = new Uri("http://localhost:64189/api/student");

            //HTTP POST
            var putTask = client.PutAsJsonAsync <NoteModelData>("api/note", note);

            putTask.Wait();

            var result = putTask.Result;

            if (result.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            //}
            //return View(savedNote);
            return(RedirectToAction("Index"));
        }