public IHttpActionResult PublicInsert(Producto_Compra producto) { if (producto == null) { return(BadRequest()); } if (PrivateInsert(producto)) { return(Ok()); } else { return(InternalServerError()); } }
private bool PrivateInsert(Producto_Compra producto) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Tienda"].ConnectionString)) { SqlCommand sqlCommand = new SqlCommand(@"INSERT INTO PRODUCTO_COMPRA(COM_ID,PRO_ID,COM_PRO_CANTIDAD,CM_PRECIO_PRODUCTO_UNIDAD) VALUES(@COM_ID,@PRO_ID,@COM_PRO_CANTIDAD,@CM_PRECIO_PRODUCTO_UNIDAD);", sqlConnection); sqlCommand.Parameters.AddWithValue("@COM_ID", producto.COM_ID); sqlCommand.Parameters.AddWithValue("@PRO_ID", producto.PRO_ID); sqlCommand.Parameters.AddWithValue("@COM_PRO_CANTIDAD", producto.COM_PRO_CANTIDAD); sqlCommand.Parameters.AddWithValue("@CM_PRECIO_PRODUCTO_UNIDAD", producto.CM_PRECIO_PRODUCTO_UNIDAD); sqlConnection.Open(); int filasAfectadas = sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); if (filasAfectadas > 0) { return(true); } else { return(false); } } }
public bool PrivateUpdate(Producto_Compra producto) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Tienda"].ConnectionString)) { SqlCommand sqlCommand = new SqlCommand(@"UPDATE PRODUCTO_COMPRA SET COM_ID=@COM_ID,PRO_ID=@PRO_ID,COM_PRO_CANTIDAD=@COM_PRO_CANTIDAD WHERE CM_ID=@ID;", sqlConnection); sqlCommand.Parameters.AddWithValue("@ID", producto.CM_ID); sqlCommand.Parameters.AddWithValue("@COM_ID", producto.COM_ID); sqlCommand.Parameters.AddWithValue("@PRO_ID", producto.PRO_ID); sqlCommand.Parameters.AddWithValue("@COM_PRO_CANTIDAD", producto.COM_PRO_CANTIDAD); sqlConnection.Open(); int filasAfectadas = sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); if (filasAfectadas > 0) { return(true); } else { return(false); } } }
public async Task Insertar(Producto_Compra producto_Compra, string token) { HttpClient client = GetClient(token); await client.PostAsync(URLInsertar, new StringContent(JsonConvert.SerializeObject(producto_Compra), Encoding.UTF8, "application/json")); }