public EmpresaViewModel Adicionar(EmpresaViewModel empresaViewModel) { var empresa = Mapper.Map <Empresa>(empresaViewModel); _empresaService.Adicionar(empresa); return(empresaViewModel); }
public ActionResult Adicionar(EmpresaDto empresaDto) { if (!ModelState.IsValid) { return(BadRequest()); } mensagens = _empresaService.Adicionar(empresaDto); return(ValidarRequest("Adicionado com sucesso.")); }
public async Task <ActionResult <EmpresaViewModel> > Adicionar(EmpresaViewModel EmpresaViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } var empresaExistente = await _empresaService.Buscar(); var empresa = _mapper.Map <Empresa>(EmpresaViewModel); if (empresaExistente != null) { empresa.Id = empresaExistente.Id; await _empresaService.Atualizar(empresa); } else { await _empresaService.Adicionar(empresa); } return(CustomResponse(empresa)); }
public bool Adicionar(EmpresaViewModel empresaViewModel, List <TelefoneViewModel> telefoneViewModel, int[] setorId, int[] cnaeSecundarioId /*, int[] funcionarioId*/) { empresaViewModel.Endereco.UFId = empresaViewModel.UFId; var empresa = Mapper.Map <EmpresaViewModel, Empresa>(empresaViewModel); empresa.Endereco = Mapper.Map <EnderecoViewModel, Endereco>(empresaViewModel.Endereco); List <Telefone> telefones = new List <Telefone>(); foreach (var item in telefoneViewModel) { telefones.Add(Mapper.Map <TelefoneViewModel, Telefone>(item)); } empresa.Telefones = telefones; foreach (var item in setorId) { empresa.Setores.Add(new Setor { SetorId = item }); } foreach (var item in cnaeSecundarioId) { empresa.CnaeSecundarios.Add(new Cnae { CnaeId = item }); } /*foreach (var item in funcionarioId) * empresa.Responsaveis.Add(new Funcionario { FuncionarioId = item });*/ BeginTransaction(); _empresaService.Adicionar(empresa); Commit(); return(true); }
public void Adicionar(EmpresaViewModel obj) { var objeto = Mapper.Map <EmpresaViewModel, Empresa>(obj); _empresaService.Adicionar(objeto); }
public void Adicionar(Empresa empresa) { _empresaService.Adicionar(empresa); }