示例#1
0
        public async Task <IActionResult> Edit(int id)
        {
            StudentLabViewModel fetchedStudentLab = null;

            using (var httpClient = ClientFactory.CreateClient("GeorestApi"))
            {
                try
                {
                    var georestClient = new GeorestClient(httpClient.BaseAddress.ToString(), httpClient);
                    fetchedStudentLab = await georestClient.GetStudentLabByIdAsync(id);
                }
                catch (SwaggerException se)
                {
                    ModelState.AddModelError("", se.Message);
                }
            }
            return(View(fetchedStudentLab));
        }
示例#2
0
        public async Task <IActionResult> Edit(StudentLabViewModel viewModel)
        {
            IActionResult result = View();

            if (ModelState.IsValid)
            {
                using (var httpClient = ClientFactory.CreateClient("GeorestApi"))
                {
                    try
                    {
                        var georestClient = new GeorestClient(httpClient.BaseAddress.ToString(), httpClient);
                        await georestClient.UpdatStudentLabAsync(viewModel.Id, Mapper.Map <StudentLabInputViewModel>(viewModel));

                        result = RedirectToAction(nameof(Index), viewModel.StudentId);
                    }
                    catch (SwaggerException se)
                    {
                        ModelState.AddModelError("", se.Message);
                    }
                }
            }

            return(result);
        }