Пример #1
0
 public void Atualizar(Paciente pacienteNovo)
 {
     repositorio.Atualizar(pacienteNovo);
 }
Пример #2
0
        public void Put([FromBody] Paciente value)
        {
            #region Validaçãoes
            if (value.Id <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                {
                    Content      = new StringContent("Paciente inválido."),
                    ReasonPhrase = "Campo inválido"
                });
            }

            if (!string.IsNullOrEmpty(value.Cpf))
            {
                if (!Validacoes.ValidaCpf(value.Cpf))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                    {
                        Content      = new StringContent("Cpf inválido."),
                        ReasonPhrase = "Campo inválido"
                    });
                }
                else
                {
                    value.Cpf = value.Cpf.Replace(".", "").Replace("-", "");
                }
            }

            if (!string.IsNullOrEmpty(value.Cep))
            {
                if (!Validacoes.ValidaCep(value.Cep))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                    {
                        Content      = new StringContent("Cep inválido."),
                        ReasonPhrase = "Campo inválido"
                    });
                }
                else
                {
                    value.Cep = value.Cep.Replace("-", "");
                }
            }

            if (string.IsNullOrWhiteSpace(value.Nome))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                {
                    Content      = new StringContent("Nome inválido."),
                    ReasonPhrase = "Campo inválido"
                });
            }

            if (!Validacoes.ValidaDataNascimento(value.DataNascimento))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                {
                    Content      = new StringContent("Data de nascimento inválida."),
                    ReasonPhrase = "Campo inválido"
                });
            }

            if (!Validacoes.ValidaCelular(value.Celular))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                {
                    Content      = new StringContent("Celular inválido."),
                    ReasonPhrase = "Campo inválido"
                });
            }

            if (!string.IsNullOrEmpty(value.Telefone))
            {
                if (!Validacoes.ValidaTelefone(value.Telefone))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                    {
                        Content      = new StringContent("Telefone inválido."),
                        ReasonPhrase = "Campo inválido"
                    });
                }
            }
            #endregion

            using (var repositorio = new PacienteRepositorio(new Connection(new System.Data.SqlClient.SqlConnection())))
            {
                repositorio.Atualizar(value);
            }
        }