Beispiel #1
0
        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)));
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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);
        }