private String BuildInsertCommandOrderd(OrderdFlight flight) { String command; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Values('{0}', '{1}', '{2}')", flight.FlightID, flight.FullName, flight.Email); // use a string builder to create the dynamic string String prefix = "INSERT INTO Ordered_Flights " + "(Flight_ID,Full_Name,Passenger_Email) "; command = prefix + sb.ToString(); return(command); }
//-------------------------------------------------------------------------------------------------- // This method inserts a flight to the orderd flights table //-------------------------------------------------------------------------------------------------- public int DBSinsertOrderdFlight(OrderdFlight orderdflight) { SqlConnection con; SqlCommand cmd; try { con = connect("DBConnectionString"); // create the connection } catch (Exception ex) { // write to log throw (ex); } String cStr = BuildInsertCommandOrderd(orderdflight); // helper method to build the insert string cmd = CreateCommand(cStr, con); // create the command try { int numEffected = cmd.ExecuteNonQuery(); // execute the command //for (int i = 0; i < flight.Routes.Count; i++) //{ // cStr = BuildInsertCommandRoute(flight.Id,flight,; //} return(numEffected); } catch (Exception ex) { return(0); // write to log throw (ex); } finally { if (con != null) { // close the db connection con.Close(); } } }
public void Post([FromBody] OrderdFlight oflt1) { oflt1.insertOrderdFlight(); }