Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixing shit
  • Loading branch information
sec11008 committed Dec 2, 2015
2 parents 023ae90 + 711f8fe commit 57d7765
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
Expand Up @@ -16,6 +16,11 @@ namespace TeamDBAwesome.Controllers
MySqlService dbService = new MySqlService();

payment.Type = payment.Type.ToUpper();

if(payment.is_default != 0 || payment.is_default != 1)
{
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}

if(payment.Type == "CC")
{
Expand Down
32 changes: 10 additions & 22 deletions TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
Expand Up @@ -15,30 +15,18 @@ namespace TeamDBAwesome.Controllers
// GET: api/Test
public HttpResponseMessage Get()
{
//make a test customer
Customer test = new Customer();
test.Address = "test";
test.City = "test";
test.Company = "test";
test.Country = "test";
test.CustomerID = 10;
test.Email = "test@test.com";
test.Fax = "9109153999";
test.FName = "test";
test.LName = "test";
test.PersonID = 10;
test.Phone = "9109153999";
test.Post = "06066";
test.State = "CT";
test.SupportRepId = 0;

//make an instance of the sql controller
Payment test = new Payment
{
CustomerId = 7,
Type = "GP",
token = "54321",
email = "fuck@fuck.com",
is_default = 1
};

MySqlService sqlS = new MySqlService();
//try and add the new user
//int ID = sqlS.AddNewUser(test);
//int ID = 0;

sqlS.UpdateCustomer(test);
sqlS.AddPayment(test);

//Customer customer = sqlS.GetCustomer(3);

Expand Down
1 change: 1 addition & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Payment.cs
Expand Up @@ -14,5 +14,6 @@ namespace TeamDBAwesome.Models
public string cardnum { get; set; }
// needs to be in yyyy-mm-dd format
public string expr_date { get; set; }
public int is_default { get; set; }
}
}
25 changes: 21 additions & 4 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Expand Up @@ -143,24 +143,41 @@ namespace TeamDBAwesome.SqlService
bool open = this.OpenConnection();

if (open == true)
{
{

string new_payment = "insert into chinook.payment(CustomerId,IsDefault) VALUES (" + payment.CustomerId + "," + payment.is_default + ")";

MySqlCommand command = new MySqlCommand(new_payment, 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 newPayId = command.ExecuteScalar() + "";

string PayTypeInsert;

if (payment.Type == "CC")
{

PayTypeInsert = "insert into creditcard(PayId,CreditCardNumber,ExpirationDate) VALUES (" + newPayId + "," +
payment.cardnum + ",\"" + payment.expr_date + "\")";
}
else if (payment.Type == "AP")
{

PayTypeInsert = "insert into applepay(PayId,ApplePayToken) VALUES (" + newPayId + "," +
payment.token + ")";
}
else if (payment.Type == "GP")
{

PayTypeInsert = "insert into googlepay(PayId,GoogleEmail,GoogleToken) VALUES (" + newPayId + ",\"" +
payment.email + "\"," + payment.token + ")";
}
else
{
return 1;
}
command = new MySqlCommand(PayTypeInsert, SqlConn);
command.ExecuteNonQuery();
}

return 0;
Expand Down

0 comments on commit 57d7765

Please sign in to comment.