public ActionResult Index()
        {
            PacienteVM viewModel = new PacienteVM();

            viewModel.HandleRequest();

            return View(viewModel);
        }
        public ActionResult BuscarPaciente(string cpf)
        {
            cpf = cpf.Replace(".", "").Replace("-", "");

            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 identity = (ClaimsPrincipal)Thread.CurrentPrincipal;

            var response    = client.GetAsync("Paciente?cpf=" + cpf).Result;
            var EmpResponse = response.Content.ReadAsStringAsync().Result;

            var paciente = JsonConvert.DeserializeObject <List <AgendaDTL.Paciente> >(EmpResponse).FirstOrDefault();

            if (paciente == null)
            {
                return(View());
            }

            var model = new PacienteVM()
            {
                Id             = paciente.Id,
                DataNascimento = paciente.DataNascimento,
                Cpf            = paciente.Cpf,
                Celular        = paciente.Celular,
                Email          = paciente.Email,
                Nome           = paciente.Nome,
                Telefone       = paciente.Telefone,
                Dependente     = new Dependente()
                {
                    DataNascimento = DateTime.Now.AddDays(-200)
                }
            };

            response    = client.GetAsync("DependentePaciente?idPaciente=" + model.Id).Result;
            EmpResponse = response.Content.ReadAsStringAsync().Result;

            //Deserializing the response recieved from web api and storing into the Employee list
            var dependentes = JsonConvert.DeserializeObject <List <AgendaDTL.DependentePaciente> >(EmpResponse);

            model.Dependentes = new List <Dependente>();
            foreach (var dependente in dependentes)
            {
                model.Dependentes.Add(
                    new Dependente()
                {
                    Id             = dependente.Id,
                    DataNascimento = dependente.DataNascimento,
                    //Celular = dependente.Celular,
                    Nome = dependente.Nome,
                    //Telefone = dependente.Telefone,
                    IdPaciente = dependente.IdPaciente
                });
            }
            return(View(model));
        }
        //[ValidateAntiForgeryToken]
        public JsonResult Edit(PacienteVM paciente)
        {
            string           jsonString;
            var              pacienteValidator = new PacienteEditValidator();
            ValidationResult pacienteValidado  = pacienteValidator.Validate(paciente);

            if (pacienteValidado.IsValid)
            {
                return(Json(new { success = false, responseText = pacienteValidado.Errors }, JsonRequestBehavior.AllowGet));
            }
            jsonString = this.jsonConfig.Serialize(this.paciente.Edit(paciente));
            return(Json(jsonString, JsonRequestBehavior.AllowGet));
        }
Beispiel #4
0
        public ActionResult Editar(PacienteVM model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    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 identity = (ClaimsPrincipal)Thread.CurrentPrincipal;

                    var response = client.PutAsync("Paciente",
                                                   new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("Id", model.Id.ToString()),
                        new KeyValuePair <string, string>("IdClinicaDeCadastro", identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault()),
                        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) ? null : model.Telefone.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", "")),
                        new KeyValuePair <string, string>("Celular", model.Celular.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", "")),
                    })).Result;

                    if (!response.IsSuccessStatusCode)
                    {
                        ModelState.AddModelError(string.Empty, response.Content.ReadAsStringAsync().Result);
                        RedirectToAction("Index");
                    }

                    if (response.IsSuccessStatusCode)
                    {
                        this.ShowMessage("Paciente Salvo.", "Sucesso!");
                        return(View(model));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, response.Content.ReadAsStringAsync().Result);
                        return(View(model));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex);
                    return(View(model));
                }
            }
            return(View(model));
        }
Beispiel #5
0
        public Models.Paciente Edit(PacienteVM model) {
            var paciente = DB.Paciente.Find(model.Id);

            paciente.PrimerNombre = model.PrimerNombre;
            paciente.SegundoNombre = model.SegundoNombre;
            paciente.PrimerApellido = model.PrimerApellido;
            paciente.SegundoApellido = model.SegundoApellido;
            paciente.Direccion = model.Direccion;
            paciente.Telefono = model.Telefono;
            paciente.CodigoPaciente = model.CodigoPaciente;
            paciente.FechaNacimiento = model.FechaNacimiento;
            paciente.Ocupacion = model.Ocupacion;
            paciente.TipoSangreId = model.TipoSangreId;

            DB.SaveChanges();
            return paciente;
        }
        public ActionResult Index(PacienteVM viewModel)
        {
            viewModel.IsValid = ModelState.IsValid;
            viewModel.HandleRequest();

            if (viewModel.IsValid)
            {
                ModelState.Clear();
            }
            else
            {
                foreach(KeyValuePair<string, string> item in viewModel.ValidationErros)
                {
                    ModelState.AddModelError(item.Key, item.Value);
                }
            }

            return View(viewModel);
        }
Beispiel #7
0
 public Models.Paciente Store(PacienteVM model)
 {
     var paciente = new Models.Paciente() {
         PrimerNombre = model.PrimerNombre,
         SegundoNombre = model.SegundoNombre,
         PrimerApellido = model.PrimerApellido,
         SegundoApellido = model.SegundoApellido,
         Direccion = model.Direccion,
         Telefono = model.Telefono,
         CodigoPaciente = "",
         FechaNacimiento = model.FechaNacimiento,
         Ocupacion = model.Ocupacion,
         TipoSangreId = model.TipoSangreId,
         SexoId = model.SexoId,
     };
     DB.Paciente.Add(paciente);
     DB.SaveChanges();
     return paciente;
 }
Beispiel #8
0
        public ActionResult Adicionar(PacienteVM model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Dependente != null)
                    {
                        if (model.Dependente.DataNascimento != null)
                        {
                            if (model.Dependente.DataNascimento >= DateTime.Now.AddMonths(-6) || model.Dependente.DataNascimento <= new DateTime(1900, 1, 1))
                            {
                                ModelState.AddModelError(string.Empty, "Data de nascimento do dependente está inválida.");
                                return(View(model));
                            }
                            else
                            if (string.IsNullOrWhiteSpace(model.Dependente.Nome))
                            {
                                ModelState.AddModelError(string.Empty, "Informe o nome do dependente.");
                                return(View(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 identity = (ClaimsPrincipal)Thread.CurrentPrincipal;

                    var response = client.PostAsync("Paciente",
                                                    new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("IdClinicaDeCadastro", identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault()),
                        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("-", "")),
                    })).Result;

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

                    int idPaciente = Convert.ToInt32(response.Content.ReadAsStringAsync().Result);

                    if (model.Dependente.Nome != null && model.Dependente.DataNascimento != null)
                    {
                        response = client.PostAsync("DependentePaciente",
                                                    new FormUrlEncodedContent(new[]
                        {
                            new KeyValuePair <string, string>("IdClinicaDeCadastro", identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault()),
                            new KeyValuePair <string, string>("IdPaciente", idPaciente.ToString()),
                            new KeyValuePair <string, string>("Nome", model.Dependente.Nome),
                            new KeyValuePair <string, string>("DataNascimento", model.Dependente.DataNascimento.Value.ToString("yyyy-MM-dd"))
                        })).Result;
                    }

                    if (response.IsSuccessStatusCode)
                    {
                        this.ShowMessage("Paciente Salvo.", "Sucesso!");
                        return(RedirectToAction("Editar", new { idPaciente = idPaciente }));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, response.Content.ReadAsStringAsync().Result);
                        return(View(model));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex);
                    return(View(model));
                }
            }
            return(View());
        }