Beispiel #1
0
        public async Task <IActionResult> Create(ClienteViewModel clienteViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(clienteViewModel));
            }

            var cliente = _mapper.Map <Cliente>(clienteViewModel);

            cliente.DataCadastro = DateTime.Now;

            await _clienteRepository.Adicionar(cliente);

            foreach (var item in clienteViewModel.PlanoId)
            {
                var plano = _planoRepository.ObterPorId(item).Result;
                plano.Cliente = cliente;
                await _planoRepository.Atualizar(plano);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public Plano ObterPorId(int id)
 {
     return(_planoRepository.ObterPorId(id));
 }
 private async Task <PlanoViewModel> ObterPlano(Guid id)
 {
     return(_mapper.Map <PlanoViewModel>(await _planoRepository.ObterPorId(id)));
 }