Пример #1
0
        public async Task <IActionResult> Create(TerritoryInsertViewModel viewModel)
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <TerritoryInsertViewModel, Territory>();
            });

            IMapper   mapper = configuration.CreateMapper();
            Territory dto    = mapper.Map <Territory>(viewModel);

            try
            {
                await _TerritoryService.Create(dto);

                return(RedirectToAction("Index", "Territory"));
            }
            catch (RPGException ex)
            {
                ViewBag.ValidationErrors = ex.Errors;
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }
            return(View());
        }
Пример #2
0
 public IActionResult Post([FromBody] TerritoryDto dto)
 {
     return(Ok(new { id = TerritoryService.Create(dto) }));
 }