示例#1
0
        public async Task <IActionResult> Create([Bind("Id,HomeLoginId,NivelAcessoId")] UsuariosRoles usuariosRoles)
        {
            if (ModelState.IsValid)
            {
                _context.Add(usuariosRoles);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(usuariosRoles));
        }
        public async Task <IActionResult> Create([Bind("Descricao,Id,Name,NormalizedName,ConcurrencyStamp")] NivelAcesso nivelAcesso)
        {
            if (ModelState.IsValid)
            {
                _agendaOdontologica.Add(nivelAcesso);
                await _agendaOdontologica.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nivelAcesso));
        }
        //[Authorize(Roles = "Administrador")]
        public async Task <IActionResult> Create([Bind("Id,Especialidade")] Especializacao especializacao)
        {
            if (ModelState.IsValid)
            {
                _agendaOdontologica.Add(especializacao);
                await _agendaOdontologica.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(especializacao));
        }
        //[Authorize(Roles = "Administrador")]
        public async Task <IActionResult> Create([Bind("Id,NomePaciente,RG,CPF,Endereço,CEP,ValorTratamento,FormaDePagamento")] Paciente paciente)
        {
            if (ModelState.IsValid)
            {
                _agendaOdontologica.Add(paciente);
                await _agendaOdontologica.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(paciente));
        }
        public async Task <IActionResult> Create([Bind("Id,HoraAtendimento,TempoAtemdimento,DentistaId,PacienteId,SecretariaId")] Agendamento agendamento)
        {
            try
            {
                if (agendamento.HoraAtendimento < DateTime.Now)
                {
                    return(RedirectToAction(nameof(Error), new { mensagem = " Data de Agendamento não é valido !!!" }));
                }
                // colocar o dentista tbm
                var a = _agendaOdontologica.Agendamentoes.FirstOrDefault(x => x.HoraAtendimento.Equals(agendamento.HoraAtendimento) && x.DentistaId.Equals(agendamento.DentistaId));
                if (a != null)
                {
                    return(RedirectToAction(nameof(Error), new { mensagem = " Este Agendamento já Existe !!!" }));
                }

                var b = _agendaOdontologica.Agendamentoes.FirstOrDefault(c => c.DentistaId.Equals(agendamento.DentistaId) &&
                                                                         c.HoraAtendimento.Equals(agendamento.HoraAtendimento) && c.PacienteId != agendamento.PacienteId);
                // diferente de null
                if (b != null)
                {
                    return(RedirectToAction(nameof(Error), new { mensagem = " Dentista vai atender outro paciente esse Horario !!!" }));
                }

                ViewData["DentistaId"]   = new SelectList(_agendaOdontologica.Dentistas, "Id", "Id", agendamento.DentistaId);
                ViewData["PacienteId"]   = new SelectList(_agendaOdontologica.Pacientes, "Id", "Id", agendamento.PacienteId);
                ViewData["SecretariaId"] = new SelectList(_agendaOdontologica.Secretarias, "Id", "Id", agendamento.SecretariaId);

                if (ModelState.IsValid)
                {
                    _agendaOdontologica.Add(agendamento);
                    await _agendaOdontologica.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (System.Exception e)
            {
                var ex = e.Message;
            }
            return(View(agendamento));
        }