public HttpResponseMessage AddUser(string nome, string email, string cnpj, string cell, 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 = cnpj, Celular = cell, Idade = idade, Endereco = endereco, Cep = cep, Autenticacao = autenticacao, }; Cliente_Comercio PJ = new Cliente_Comercio() { Usuario = novoUsuario, Usuario_Email = email, Usuario_id = novoUsuario.ID, }; novoUsuario.Cliente_Comercio.Add(PJ); 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 AddService(string email, string senha, string nome, string descricao, decimal preco) { try { if (usuarioObjeto.TestarSenha(senha, email) != true) { return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Usuário e/ou senha invalido(s)")); } Cliente_Comercio pj = (from comercio in vetDb.Cliente_Comercio where comercio.Usuario_Email == email select comercio).Single(); Services service = new Services() { Nome = nome, Descricao = descricao, Preco = preco, Cliente_Comercio_Email = pj.Usuario_Email, Cliente_Comercio_ID = pj.ID }; pj.Services.Add(service); vetDb.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Serviço adicionado")); } 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.Unauthorized, e.Message)); } }