Пример #1
0
        public async Task <IActionResult> Create([Bind("ConsultaID,MedicoID,PacienteID,DataConsulta,DataFinalConsulta")] Consulta consulta)
        {
            if (ModelState.IsValid)
            {
                if (consulta.DataFinalConsulta <= consulta.DataConsulta)
                {
                    ModelState.AddModelError("ProcessSubmitUpload", "A data final da consulta deve ser maior que a inicial.");
                    ViewData["MedicoID"]   = new SelectList(_context.Medicos, "MedicoID", "Nome");
                    ViewData["PacienteID"] = new SelectList(_context.Pacientes, "PacienteID", "NomePaciente");
                    return(View());
                }
                else if (_validation.ValidarConsultaMedico(consulta.MedicoID, consulta.DataConsulta))
                {
                    ModelState.AddModelError("ProcessSubmitUpload", "Já existe consulta agendada para este médico.");
                    ViewData["MedicoID"]   = new SelectList(_context.Medicos, "MedicoID", "Nome");
                    ViewData["PacienteID"] = new SelectList(_context.Pacientes, "PacienteID", "NomePaciente");
                    return(View());
                }
                _context.Add(consulta);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MedicoID"]   = new SelectList(_context.Medicos, "MedicoID", "MedicoID", consulta.MedicoID);
            ViewData["PacienteID"] = new SelectList(_context.Pacientes, "PacienteID", "PacienteID", consulta.PacienteID);
            return(View(consulta));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("MedicoID,Nome,Email,Especialidade")] Medico medico)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medico);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(medico));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("NomePaciente,Cpf,NumTelefone,Email,Rua,Numero,Bairro,Cidade")] Paciente paciente)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(paciente);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                // Log the error(uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(paciente));
        }