public HttpResponseMessage AddUser(string nome, string email, string cpf, string celular, int idade, string endereco, string cep, string senha) { try { Password password = new Password(); string senhaEncriptada = password.EncryptPassword(senha); Autenticacao autenticacao = new Autenticacao() { Senha = senhaEncriptada, Email = email, }; Models.Usuario novoUsuario = new Models.Usuario() { Nome = nome, Email = email, Cpf_Cnpj = cpf, Celular = celular, Idade = idade, Endereco = endereco, Cep = cep, Autenticacao = autenticacao, Data_cadastro = DateTime.Now }; Cliente_Pessoa pessoa = new Cliente_Pessoa() { Usuario = novoUsuario, Usuario_Email = email, Usuario_id = novoUsuario.ID, }; novoUsuario.Cliente_Pessoa.Add(pessoa); vetDb.Usuario.Add(novoUsuario); vetDb.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Bem vindo!")); } catch (DbEntityValidationException e) { String erros = ""; foreach (var erro in e.EntityValidationErrors) { System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" Erro \n ", erro.Entry.Entity.GetType().Name, erro.Entry.State); foreach (var ve in erro.ValidationErrors) { System.Diagnostics.Debug.WriteLine(" - Property: \"{0}\", Erro: \"{1}\"", ve.PropertyName, ve.ErrorMessage); erros += String.Format(" - Property: \"{0}\", Erro: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, erros)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.Unauthorized, e.Message)); } }
public HttpResponseMessage AddPet(string email, string senha, string nome, string raca, decimal peso, string tamanho, string descricao, string genero, int idade, string especie) { if (usuarioObjeto.TestarSenha(senha, email) != true) { return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Usuário e/ou senha invalido(s)")); } Cliente_Pessoa dono = (from pessoa in vetDb.Cliente_Pessoa where pessoa.Usuario_Email == email select pessoa).Single(); Pets pet = new Pets() { Nome = nome, What_pet = especie, Raca = raca, Peso = peso, Tamanho = tamanho, Descricao = descricao, Genero = genero, Idade = idade, Cliente_pessoa_Email = dono.Usuario_Email, Cliente_pessoa_id = dono.ID, }; dono.Pets.Add(pet); try { vetDb.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Pet adicionado com sucesso!")); } catch (DbEntityValidationException e) { String erros = ""; foreach (var erro in e.EntityValidationErrors) { System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" Erro \n ", erro.Entry.Entity.GetType().Name, erro.Entry.State); foreach (var ve in erro.ValidationErrors) { System.Diagnostics.Debug.WriteLine(" - Property: \"{0}\", Erro: \"{1}\"", ve.PropertyName, ve.ErrorMessage); erros += String.Format(" - Property: \"{0}\", Erro: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, erros)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message)); } }