public ActionResult Cadastrar(ClienteInsertViewModel viewModel) { ClienteService svc = new ClienteService(); var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <ClienteInsertViewModel, ClienteDTO>(); }); IMapper mapper = configuration.CreateMapper(); // new SERService().GetSERByID(4); //Transforma o ClienteInsertViewModel em um ClienteDTO ClienteDTO dto = mapper.Map <ClienteDTO>(viewModel); try { svc.Insert(dto); //Se funcionou, redireciona pra página inicial return(RedirectToAction("Home", "Index")); } catch (NecoException ex) { //Se caiu aqui, o ClienteService lançou a exceção por validação de campos ViewBag.ValidationErrors = ex.Errors; } catch (Exception ex) { //Se caiu aqui, o ClienteService lançou uma exceção genérica, provavelmente por falha de acesso ao banco ViewBag.ErrorMessage = ex.Message; } //Se chegou aqui, temos erro return(View()); }
public async Task <ActionResult> Inserir(ClienteInsertViewModel viewModel) { var config = new MapperConfiguration(cfg => cfg.CreateMap <ClienteInsertViewModel, Cliente>()); var mapper = config.CreateMapper(); Cliente cliente = mapper.Map <Cliente>(viewModel); Response response = await svc.Insert(cliente); if (response.Sucesso) { return(RedirectToAction("Index")); } ViewBag.Erros = response.Mensagem; return(View()); }
public ClienteServiceTest() { _entity = _fixture.Build <Cliente>().Create(); _insertViewModel = _fixture.Create <ClienteInsertViewModel>(); _updateViewModel = _fixture.Create <ClienteUpdateViewModel>(); _mockBusiness = new Mock <IClienteBusiness>(); _exception = _fixture.Create <Exception>(); _mockMapper = new Mock <IMapper>(); _mockNotification = new Mock <INotification>(); _service = new ClienteService(_mockBusiness.Object, _mockMapper.Object); }
public async Task <IActionResult> Cadastrar(ClienteInsertViewModel clienteViewModel) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <ClienteInsertViewModel, ClienteDTO>(); }); IMapper mapper = configuration.CreateMapper(); ClienteDTO cliente = mapper.Map <ClienteDTO>(clienteViewModel); try { await _clienteService.Insert(cliente); return(RedirectToAction("Index", "Cliente")); } catch (Exception ex) { ViewBag.ErroGenerico = ex.Message; } return(View()); }
public void Inserir(ClienteInsertViewModel clienteInsertViewModel) { var mapeamento = Map <Cliente>(clienteInsertViewModel); clienteBusiness.Insert(mapeamento); }
public ActionResult Inserir([FromBody] ClienteInsertViewModel aluno) { clienteService.Inserir(aluno); return(Created("", "Inserido com Sucesso")); }