Ejemplo n.º 1
0
        public ActionResult CadastroPaciente(CadastroPacienteAgendamentoVM model)
        {
            if (!ModelState.IsValid)
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["service:ApiAddress"].ToString());
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                var response = client.PostAsync("Paciente",
                                                new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Nome", model.Nome),
                    new KeyValuePair <string, string>("Cpf", model.Cpf),
                    new KeyValuePair <string, string>("Email", model.Email),
                    new KeyValuePair <string, string>("DataNascimento", model.DataNascimento.ToString("yyyy-MM-dd")),
                    new KeyValuePair <string, string>("Telefone", string.IsNullOrWhiteSpace(model.Telefone) ? "" : model.Telefone.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", "")),
                    new KeyValuePair <string, string>("Celular", model.Celular.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", "")),
                    new KeyValuePair <string, string>("Usuario.Senha", AgendaUtils.Criptografia.RetornarMD5(model.Senha)),
                })).Result;

                if (!response.IsSuccessStatusCode)
                {
                    ModelState.AddModelError(string.Empty, response.Content.ReadAsStringAsync().Result);
                    return(View(model));
                }

                var agendamento = JsonConvert.DeserializeObject <Models.Agendamento>(Request.Cookies["agendamento"].Value);
                //string idPaciente = response.Content.ReadAsStringAsync().Result;

                response = client.PostAsync("Agendamento",
                                            new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("IdAgenda", agendamento.IdAgenda.ToString()),
                    new KeyValuePair <string, string>("IdPaciente", response.Content.ReadAsStringAsync().Result),
                    new KeyValuePair <string, string>("Data", agendamento.DataAgendamento.ToString("yyyy-MM-dd")),
                    new KeyValuePair <string, string>("Horario", agendamento.HoraAgendamento.ToString())
                })).Result;

                if (!response.IsSuccessStatusCode)
                {
                    ModelState.AddModelError(string.Empty, response.Content.ReadAsStringAsync().Result);
                    return(View(model));
                }

                var tempModel = new ProtocoloVM()
                {
                    Clinica         = "Clinicão",
                    DataAgendamento = agendamento.DataAgendamento < new DateTime(1000, 1, 1) ? DateTime.Now : agendamento.DataAgendamento,
                    HoraAgendamento = agendamento.HoraAgendamento == null ? TimeSpan.MaxValue : agendamento.HoraAgendamento,
                    Protocolo       = 123
                };

                TempData["protocolo"] = tempModel;
                return(RedirectToAction("ProtocoloAgendamento", "Home"));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Entrar(AcessoViewModel model)
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri(ConfigurationManager.AppSettings["service:ApiAddress"].ToString());
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var response = client.GetAsync("Usuario?login="******"&senha=" + AgendaUtils.Criptografia.RetornarMD5(model.Senha) +
                                           "&tipoAcesso=3").Result;

            if (!response.IsSuccessStatusCode)
            {
                ModelState.AddModelError("", "Usuário ou senha inválidos.");
                return(View(model));
            }

            var acesso = JsonConvert.DeserializeObject <AgendaDTL.Usuario>(response.Content.ReadAsStringAsync().Result);

            var agendamento = JsonConvert.DeserializeObject <Models.Agendamento>(Request.Cookies["agendamento"].Value);

            //string idPaciente = response.Content.ReadAsStringAsync().Result;

            response = client.PostAsync("Agendamento",
                                        new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("IdAgenda", agendamento.IdAgenda.ToString()),
                new KeyValuePair <string, string>("IdPaciente", acesso.idPaciente.ToString()),
                new KeyValuePair <string, string>("Data", agendamento.DataAgendamento.ToString("yyyy-MM-dd")),
                new KeyValuePair <string, string>("Horario", agendamento.HoraAgendamento.ToString())
            })).Result;

            if (!response.IsSuccessStatusCode)
            {
                ModelState.AddModelError(string.Empty, response.Content.ReadAsStringAsync().Result);
                return(View(model));
            }

            var tempModel = new ProtocoloVM()
            {
                Clinica         = "Clinicão",
                Nome            = model.Login == null ? "teste nome" : model.Login,
                DataAgendamento = agendamento.DataAgendamento < new DateTime(1000, 1, 1) ? DateTime.Now : agendamento.DataAgendamento,
                HoraAgendamento = agendamento.HoraAgendamento == null ? TimeSpan.MaxValue : agendamento.HoraAgendamento,
                Protocolo       = 123
            };

            TempData["protocolo"] = tempModel;
            return(RedirectToAction("ProtocoloAgendamento", "Home"));
        }