Example #1
0
        public async Task <IActionResult> Create([Bind("Id,Realizado")] AgendamentoViewModel agendamentoViewModel)
        {
            if (ModelState.IsValid)
            {
                var agendamento = _mapper.Map <Agendamento>(agendamentoViewModel);
                await _agendamentoService.Adicionar(agendamento);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(agendamentoViewModel));
        }
        public async Task <IActionResult> Create(AgendamentoViewModel agendamentoViewModel)
        {
            agendamentoViewModel.Pacientes = _mapper.Map <IEnumerable <PacienteViewModel> >(await _pacienteRepository.ObterTodos());
            agendamentoViewModel.Medicos   = _mapper.Map <IEnumerable <MedicoViewModel> >(await _medicoRepository.ObterTodos());

            if (!ModelState.IsValid)
            {
                return(View(agendamentoViewModel));
            }

            await _agendamentoService.Adicionar(_mapper.Map <Agendamento>(agendamentoViewModel));

            if (!OperacaoValida())
            {
                return(View(agendamentoViewModel));
            }

            TempData["Sucesso"] = "Agendamento cadastrado com sucesso!";

            return(RedirectToAction("Index"));
        }