public async Task <IActionResult> Edit(int id) { StudentResponseViewModel fetchedStudentResponse = null; using (var httpClient = ClientFactory.CreateClient("GeorestApi")) { try { var georestClient = new GeorestClient(httpClient.BaseAddress.ToString(), httpClient); fetchedStudentResponse = await georestClient.GetStudentResponseByIdAsync(id); } catch (SwaggerException se) { ModelState.AddModelError("", se.Message); } } return(View(fetchedStudentResponse)); }
public async Task <IActionResult> Edit(StudentResponseViewModel viewModel) { IActionResult result = View(); if (ModelState.IsValid) { using (var httpClient = ClientFactory.CreateClient("GeorestApi")) { try { var georestClient = new GeorestClient(httpClient.BaseAddress.ToString(), httpClient); await georestClient.UpdateStudentResponseAsync((int)viewModel.Id, Mapper.Map <StudentResponseInputViewModel>(viewModel)); result = RedirectToAction(nameof(Index)); } catch (SwaggerException se) { ModelState.AddModelError("", se.Message); } } } return(result); }