public async Task <ActionResult <SectionViewModel> > AddSection(SectionInputViewModel viewModel) { if (viewModel == null) { return(BadRequest()); } Section createdSection = await SectionService.AddSection(Mapper.Map <Section>(viewModel)).ConfigureAwait(false); return(CreatedAtAction(nameof(AddSection), new { id = createdSection.Id }, Mapper.Map <SectionViewModel>(createdSection))); }
public async Task <ActionResult <SectionViewModel> > UpdateSection(int id, SectionInputViewModel viewModel) { if (viewModel == null) { return(BadRequest()); } Section fetchedSection = await SectionService.GetById(id).ConfigureAwait(false); if (fetchedSection == null) { return(NotFound()); } Mapper.Map(viewModel, fetchedSection); await SectionService.UpdateSection(fetchedSection).ConfigureAwait(false); return(NoContent()); }
public async Task <IActionResult> Add(SectionInputViewModel viewModel) { IActionResult result = View(); if (ModelState.IsValid) { using (var httpClient = ClientFactory.CreateClient("GeorestApi")) { try { var georestClient = new GeorestClient(httpClient.BaseAddress.ToString(), httpClient); await georestClient.AddSectionAsync(viewModel); result = RedirectToAction(nameof(Index)); } catch (SwaggerException se) { ModelState.AddModelError("", se.Message); } } } return(result); }