Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,IdPaciente,IdUsuario,DataMarcadaExame,NomeExame,LocalExame")] AgendamentoExame agendamentoExame)
        {
            TwilioSMS twilioSMS  = new TwilioSMS();
            Email     email      = new Email();
            var       paciente   = db.Paciente.Find(agendamentoExame.IdPaciente);
            var       nomeMedico = db.Usuarios.Find(agendamentoExame.IdUsuario);

            var msgConfirmacaoCel = String.Format(_msgConfirmacaoAgendamentoCel, agendamentoExame.NomeExame,
                                                  agendamentoExame.DataMarcadaExame, nomeMedico.Nome, agendamentoExame.LocalExame);

            var msgConfirmacaoEmail = String.Format(_msgConfirmacaoAgendamentoEmail, agendamentoExame.NomeExame,
                                                    agendamentoExame.DataMarcadaExame, nomeMedico.Nome, agendamentoExame.LocalExame);

            if (ModelState.IsValid)
            {
                db.AgendamentoExame.Add(agendamentoExame);
                db.SaveChanges();

                if (!paciente.Telefone.IsNullOrWhiteSpace())
                {
                    twilioSMS.SendTwilioSMS(paciente.Telefone, msgConfirmacaoCel);
                }

                if (!paciente.Email.IsNullOrWhiteSpace())
                {
                    email.SendEmail(paciente.Email, _subjectConfirmacaoAgendamentoEmail, msgConfirmacaoEmail);
                }

                return(RedirectToAction($"Index"));
            }

            ViewBag.IdPaciente = new SelectList(db.Paciente, "Id", "NomeCompleto", agendamentoExame.IdPaciente);
            ViewBag.IdUsuario  = new SelectList(db.Usuarios, "Id", "Nome", agendamentoExame.IdUsuario);
            return(View(agendamentoExame));
        }
Exemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            AgendamentoExame agendamentoExame = db.AgendamentoExame.Find(id);
            Email            email            = new Email();
            TwilioSMS        twilioSMS        = new TwilioSMS();

            var paciente   = db.Paciente.Find(agendamentoExame.IdPaciente);
            var nomeMedico = db.Usuarios.Find(agendamentoExame.IdUsuario);

            var msgCancelamentoCel = String.Format(_msgCancelAgendamentoCel, agendamentoExame.NomeExame,
                                                   agendamentoExame.DataMarcadaExame, nomeMedico.Nome, agendamentoExame.LocalExame);

            var msgCancelamentoEmail = String.Format(_msgCancelAgendamentoEmail, agendamentoExame.NomeExame,
                                                     agendamentoExame.DataMarcadaExame, nomeMedico.Nome, agendamentoExame.LocalExame);

            if (!paciente.Telefone.IsNullOrWhiteSpace())
            {
                twilioSMS.SendTwilioSMS(paciente.Telefone, msgCancelamentoCel);
            }

            if (!paciente.Email.IsNullOrWhiteSpace())
            {
                email.SendEmail(paciente.Email, _subjectCancelAgendamentoEmail, msgCancelamentoEmail);
            }

            db.AgendamentoExame.Remove(agendamentoExame);
            db.SaveChanges();
            return(RedirectToAction($"Index"));
        }