Пример #1
0
        public async Task <ActionResult <StudentLabViewModel> > AddStudentLab(StudentLabInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }

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

            return(CreatedAtAction(nameof(AddStudentLab), new { id = createdLab.Id }, Mapper.Map <StudentLabViewModel>(createdLab)));
        }
Пример #2
0
        public async Task <IActionResult> Add(StudentLabInputViewModel viewModel)
        {
            IActionResult result = View();

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

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

            return(result);
        }
Пример #3
0
        public async Task <ActionResult <StudentLabViewModel> > UpdatStudentLab(int id, StudentLabInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(BadRequest());
            }
            StudentLab fetchedLab = await LabService.GetById(id).ConfigureAwait(false);

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

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

            return(NoContent());
        }