public async Task <IActionResult> Create(GeneroInsertViewModel viewModel) { try { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <GeneroInsertViewModel, GeneroDTO>(); }); IMapper mapper = configuration.CreateMapper(); GeneroDTO genero = mapper.Map <GeneroDTO>(viewModel); await _generoService.Create(genero); return(RedirectToAction("Index", "Home")); } catch (MSException ex) { ViewBag.ValidationErrors = ex.Errors; } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; } return(View()); }
public IActionResult Create([FromBody] GeneroInsertDto item) { try { var id = _service.Create(item); return(CreatedAtAction(nameof(Find), new { id }, item)); } catch (Exception ex) { return(StatusCode(500, ex)); } }