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()); }
public IActionResult Post([FromBody] TerritoryDto dto) { return(Ok(new { id = TerritoryService.Create(dto) })); }