示例#1
0
        public async Task <ActionResult <InstructorLabViewModel> > AddInstructorLab(InstructorLabInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }

            InstructorLab createdLab = await LabService.AddLab(Mapper.Map <InstructorLab>(viewModel)).ConfigureAwait(false);

            //return CreatedAtAction(nameof(AddStudentLab), new { id = createdLab.Id }, Mapper.Map<InstructorLabViewModel>(createdLab));
            return(Ok(createdLab));
        }
        public async Task <IActionResult> Add(InstructorLabInputViewModel viewModel)
        {
            IActionResult result = View();

            if (ModelState.IsValid)
            {
                using (var httpClient = ClientFactory.CreateClient("GeorestApi"))
                {
                    try
                    {
                        var georestClient = new GeorestClient(httpClient.BaseAddress.ToString(), httpClient);
                        await georestClient.AddInstructorLabAsync(viewModel);

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

            return(result);
        }
示例#3
0
        public async Task <ActionResult <InstructorLabViewModel> > UpdateInstructorLab(int id, InstructorLabInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }
            InstructorLab fetchedLab = await LabService.GetById(id).ConfigureAwait(false);

            if (fetchedLab == null)
            {
                return(NotFound());
            }

            Mapper.Map(viewModel, fetchedLab);
            await LabService.UpdateLab(fetchedLab).ConfigureAwait(false);

            return(NoContent());
        }