public IActionResult Create(Paciente paciente) { ViewBag.error = null; try { if (_context.Pacientes.Where(e => e.Cpf == paciente.Cpf).Count() > 0) { throw new Exception("Já existe um paciente com esse CPF cadastrado."); } if (_context.Pacientes.Where(e => e.Email == paciente.Email).Count() > 0) { throw new Exception("Já existe um paciente com esse E-mail cadastrado."); } _context.Pacientes.Add(paciente); _context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.error = e.Message; ViewBag.Convenio = new SelectList(_context.Convenios, "Id", "Nome"); return(View()); } }
public IActionResult Create(Agendamentos agendamento) { ViewBag.error = null; try { var diaVerificacao = agendamento.DataAtendimento.Day; var mesVerificacao = agendamento.DataAtendimento.Month; var anoVerificacao = agendamento.DataAtendimento.Year; var qtdAgendamentosMarcados = _context.Agendamentos.Where(e => e.ClinicaId == agendamento.ClinicaId && e.DataAtendimento.Day == diaVerificacao && e.DataAtendimento.Month == mesVerificacao && e.DataAtendimento.Year == anoVerificacao); if (qtdAgendamentosMarcados.Count() >= 20) { throw new Exception("Não é possível realizar mais de 20 agendamentos por dia para a clínica."); } var pacienteJaAgendado = _context.Agendamentos.Where(e => e.PacienteId == agendamento.PacienteId && e.DataAtendimento.Day == diaVerificacao && e.DataAtendimento.Month == mesVerificacao && e.DataAtendimento.Year == anoVerificacao); if (pacienteJaAgendado.Count() > 0) { throw new Exception("Já existe um agendamento para esse paciente nessa data."); } _context.Agendamentos.Add(agendamento); _context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.Clinica = new SelectList(_context.Clinicas, "Id", "Nome"); ViewBag.Paciente = new SelectList(_context.Pacientes, "Id", "Nome"); ViewBag.error = e.Message; return(View()); } }
public IActionResult Create(Convenio convenio) { ViewBag.error = null; try { if (_context.Convenios.Where(e => e.Nome == convenio.Nome).Count() > 0) { throw new Exception("Já existe um Convênio criado com esse nome."); } _context.Convenios.Add(convenio); _context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.error = e.Message; return(View()); } }
public IActionResult Create(Clinica clinica) { ViewBag.error = null; try { if (_context.Clinicas.Where(e => e.Cnpj == clinica.Cnpj).Count() > 0) { throw new Exception("Já existe uma clínica criada com esse CNPJ"); } _context.Clinicas.Add(clinica); _context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.error = e.Message; return(View()); } }