コード例 #1
0
        public async Task <IActionResult> Edit(int id)
        {
            InstructorLabViewModel fetchedInstructorLab = null;

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

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

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

            return(result);
        }