public async Task <IActionResult> Create(ClientInsertViewModel viewModel) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <ClientInsertViewModel, ClientDTO>(); }); IMapper mapper = configuration.CreateMapper(); ClientDTO dto = mapper.Map <ClientDTO>(viewModel); try { _clientService.Create(dto); return(RedirectToAction("Home", "Index")); } catch (NecoException ex) { ViewBag.ValidationErrors = ex.Errors; } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; } return(View()); }
public async Task <ActionResult> Register(ClientInsertViewModel viewModel) { Response response = new Response(); if (ModelState.IsValid) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <ClientInsertViewModel, ClientDTO>(); }); IMapper mapper = configuration.CreateMapper(); ClientDTO dto = mapper.Map <ClientDTO>(viewModel); response = await _service.Insert(dto); //Se funcionou, redireciona pra página inicial if (response.Success) { return(RedirectToAction("Index", "Client")); } else { ViewBag.ErrorMessage = response.Errors; return(this.View()); } } else { ViewBag.ErrorMessage = response.Errors; return(this.View()); } }
public async Task <IActionResult> Insert(ClientInsertViewModel viewModel) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <ClientInsertViewModel, ClientDTO>(); }); IMapper mapper = configuration.CreateMapper(); // new SERService().GetSERByID(4); //Transforma o ClienteInsertViewModel em um ClienteDTO ClientDTO dto = mapper.Map <ClientDTO>(viewModel); try { await this._clientService.Insert(dto); return(RedirectToAction("Index", "Client")); } catch (Exception ex) { ViewBag.Erros = ex.Message; } return(View()); }
public async Task <ActionResult> Update(int id) { Response response = new Response(); if (id == 0) { return(View(new ClientInsertViewModel())); } else { DataResponse <ClientDTO> clientDTO = await _service.GetByID(id); ClientDTO dto = clientDTO.Data.FirstOrDefault(); var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <ClientDTO, ClientInsertViewModel>(); }); IMapper mapper = configuration.CreateMapper(); ClientInsertViewModel insertViewModel = mapper.Map <ClientInsertViewModel>(dto); return(View(insertViewModel)); } //response = await _service.Update(dto); ////Se funcionou, redireciona pra página inicial //if (response.Success) //{ // return RedirectToAction("Index", "Client"); //} //else //{ // ViewBag.ErrorMessage = response.Errors; // return this.View(); //} }