public HttpResponseMessage Login(Lib_Primavera.Model.Vendedor vendedor) { Lib_Primavera.Model.RespostaErro erro = new Lib_Primavera.Model.RespostaErro(); erro = Lib_Primavera.PriIntegrationVendedor.CheckLoginDetails(vendedor); if (erro.Erro == 0) { try { Lib_Primavera.Model.Vendedor myVendedor = Lib_Primavera.PriIntegrationVendedor.GetVendedor(Int32.Parse(vendedor.Id)); myVendedor.Chefe = vendedor.Chefe; myVendedor.Role = vendedor.Role; var response = Request.CreateResponse( HttpStatusCode.Accepted, myVendedor); string uri = Url.Link("DefaultApi", new { Id = vendedor.Id }); //response.Headers.Location = new Uri(uri); return(response); } catch (Exception e) { Console.WriteLine(e); } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public Lib_Primavera.Model.Vendedor Get(String id) { Lib_Primavera.Model.Vendedor vendedor = PharmaCRM.Lib_Primavera.PriIntegration.GetVendedor(id); if (vendedor == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } else { return(vendedor); } }
// POST: api/vendedores/ public HttpResponseMessage Post(Lib_Primavera.Model.Vendedor vendedor) { Lib_Primavera.Model.RespostaErro erro = new Lib_Primavera.Model.RespostaErro(); erro = Lib_Primavera.PriIntegration.InsereVendedorObj(vendedor); if (erro.Erro == 0) { var response = Request.CreateResponse(HttpStatusCode.Created, vendedor); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public HttpResponseMessage Post(Lib_Primavera.Model.Vendedor vendedor) { Lib_Primavera.Model.RespostaErro erro = new Lib_Primavera.Model.RespostaErro(); erro = Lib_Primavera.PriIntegrationVendedor.InsereVendedorObj(vendedor); if (erro.Erro == 0) { SqlConnection conn = new SqlConnection(); SqlCommand cmd = new SqlCommand(); conn.ConnectionString = "Data Source=User-PC\\PRIMAVERA;" + "Initial Catalog=PrimaveraExtension;" + "User id=sa;" + "Password=Feup2014;"; cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = "INSERT INTO Authentication (Username, Password, Role, Vendedor) VALUES (@param1,@param2,@param3,@param4)"; cmd.Parameters.AddWithValue("@param1", vendedor.Username); cmd.Parameters.AddWithValue("@param2", vendedor.Password); cmd.Parameters.AddWithValue("@param3", vendedor.Role); cmd.Parameters.AddWithValue("@param4", vendedor.Id); try { conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } var response = Request.CreateResponse( HttpStatusCode.Created, vendedor); string uri = Url.Link("DefaultApi", new { Id = vendedor.Id }); //response.Headers.Location = new Uri(uri); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// PUT: api/vendedores/1 public HttpResponseMessage Put(string id, Lib_Primavera.Model.Vendedor vendedor) { Lib_Primavera.Model.RespostaErro erro = new Lib_Primavera.Model.RespostaErro(); try { erro = Lib_Primavera.PriIntegration.UpdVendedor(id, vendedor); if (erro.Erro == 0) { return(Request.CreateResponse(HttpStatusCode.OK, erro.Descricao)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, erro.Descricao)); } } catch (Exception exc) { return(Request.CreateResponse(HttpStatusCode.BadRequest, erro.Descricao)); } }
// GET: api/vendedores/3 public Vendedor Get(string id) { Lib_Primavera.Model.Vendedor vendedor = Lib_Primavera.PriIntegration.GetVendedor(id); return(vendedor); }