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))); }
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); }
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()); }