Skip to content

Commit

Permalink
finished untested add customer API
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Mill committed Nov 4, 2015
1 parent eaadfe1 commit 8d4a295
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using TeamDBAwesome.Models;

namespace TeamDBAwesome.SqlService
{
Expand Down Expand Up @@ -69,5 +70,53 @@ private bool CloseConnection()
return false;
}
}

public bool AddNewUser(Customer newCust)
{
bool open = this.OpenConnection();

if(open == true)
{

//do the update into person
string update = "INSERT into chinook.Person(LastName,FirstName,Address,City,State,PostalCode,Country,Phone,Fax,Email)" +
" VALUES ("+newCust.LName+","+newCust.FName + "," + newCust.Address + "," + newCust.City + "," + newCust.State +
"," + newCust.Post + "," + newCust.Country + "," + newCust.Phone + "," + newCust.Fax + "," + newCust.Email + ")";

MySqlCommand command = new MySqlCommand(update, SqlConn);
command.ExecuteNonQuery();

//now we need to get the primary key from that recent update
string pk_query = "SELECT LAST_INSERT_ID()";
command = new MySqlCommand(pk_query, SqlConn);
string newPersonID = command.ExecuteScalar() + "";

//now we can put into Customer
if(newCust.Company=="" || newCust.Company == null)
{
update = "INSERT INTO chinook.Customer(Company,SupportRepID,PersonID) VALUES (" + newCust.Company + "," + newCust.SupportRepId +
"," + newPersonID + ")";
}
else
{
update = "INSERT INTO chinook.Customer(Company,SupportRepID,PersonID) VALUES (" + "NULL" + "," + newCust.SupportRepId +
"," + newPersonID + ")";
}

command = new MySqlCommand(update, SqlConn);
command.ExecuteNonQuery();

//close the connection
this.CloseConnection();

return true;
}
else
{
return false;
}


}
}
}

0 comments on commit 8d4a295

Please sign in to comment.