Skip to content

Commit

Permalink
working API for add customer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Mill committed Nov 11, 2015
1 parent 9418def commit 1b9bc30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public HttpResponseMessage Get()
test.Phone = "9109153999";
test.Post = "06066";
test.State = "CT";
test.SupportRepId = 0;
test.SupportRepId = 1;

//make an instance of the sql controller
MySqlService sqlS = new MySqlService();
Expand Down
20 changes: 14 additions & 6 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public int AddNewUser(Customer newCust)

//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 + ")";
" 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();
Expand All @@ -91,15 +91,23 @@ public int AddNewUser(Customer newCust)
command = new MySqlCommand(pk_query, SqlConn);
string newPersonID = command.ExecuteScalar() + "";

//it turns out that CustomerID isn't an auto incrementing value because people suck, so we need to get that
string cust_pk_query = "SELECT CustomerID FROM customer ORDER BY CustomerId DESC LIMIT 1";
command = new MySqlCommand(cust_pk_query, SqlConn);
string nextCustIDstring = command.ExecuteScalar() + "";
int next_custID_int = int.Parse(nextCustIDstring);
next_custID_int = next_custID_int + 1;
nextCustIDstring = next_custID_int.ToString();

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

Expand Down

0 comments on commit 1b9bc30

Please sign in to comment.