diff --git a/TeamDBAwesome/TeamDBAwesome/Controllers/GetCustomerInvoiceController.cs b/TeamDBAwesome/TeamDBAwesome/Controllers/GetCustomerInvoiceController.cs index 4e02ba2..24f05ed 100644 --- a/TeamDBAwesome/TeamDBAwesome/Controllers/GetCustomerInvoiceController.cs +++ b/TeamDBAwesome/TeamDBAwesome/Controllers/GetCustomerInvoiceController.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Web.Http; using TeamDBAwesome.SqlService; using TeamDBAwesome.Models; +using Newtonsoft.Json; namespace TeamDBAwesome.Controllers { @@ -17,11 +18,11 @@ namespace TeamDBAwesome.Controllers MySqlService sql = new MySqlService(); - List invoiceList = new List(); + List invoiceList = sql.getInvoices(custId); - int nextInvoice = sql.createInvoice(custId, payId, orderId); + string serialized = JsonConvert.SerializeObject(invoiceList); - message.Content = new StringContent(nextInvoice.ToString()); + message.Content = new StringContent(serialized); return message; } diff --git a/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs b/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs index 172fe0e..37ae4a4 100644 --- a/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs +++ b/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs @@ -312,7 +312,88 @@ namespace TeamDBAwesome.SqlService if(open == true) { string query = "SELECT invoice.invoiceid, invoice.customerid, invoice.invoicedate, invoice.billingaddress, invoice.billingcity, " + - "invoice.billingstate, invoice.billingcountry, invoice.billingpostalcode, invoice.total, invoice.payid" + "invoice.billingstate, invoice.billingcountry, invoice.billingpostalcode, invoice.total, invoice.payid, payment.payId, " + + "payment.IsDefault, applepay.ApplePayToken, googlepay.GoogleToken, googlepay.GoogleEmail, creditcard.CreditCardNumber, " + + "creditcard.ExpirationDate " + + "from invoice " + + "left join payment on invoice.payid = payment.payid " + + "left join applepay on invoice.payid = applepay.PayId " + + "left join googlepay on invoice.payid = googlepay.PayId " + + "left join creditcard on invoice.payid = creditcard.PayId " + + //"where invoice.InvoiceId = " + custId; + "where invoice.customerId = " + custId; + + MySqlCommand cmd = new MySqlCommand(query, SqlConn); + MySqlDataReader reader = cmd.ExecuteReader(); + string Correct_Token; + while (reader.Read()) + { + string appleToken = GetDBString("ApplePayToken", reader); + string googleToken = GetDBString("GoogleToken", reader); + if(String.IsNullOrEmpty(appleToken)) + { + Correct_Token = googleToken; + } + else + { + Correct_Token = appleToken; + } + + int payid = 0, IsDef = 0; + string EmptyPayId = GetDBString("payId", reader); + if(String.IsNullOrEmpty(EmptyPayId)) + { + payid = 0; + } + else + { + payid = int.Parse(EmptyPayId); + } + string EmptyDefault = GetDBString("IsDefault", reader); + if(String.IsNullOrEmpty(EmptyDefault)) + { + IsDef = 0; + } + else + { + IsDef = int.Parse(EmptyDefault); + } + + Payment LoadPayment = new Payment + { + PayId = payid, + is_default = IsDef, + token = Correct_Token, + email = GetDBString("GoogleEmail", reader), + cardnum = GetDBString("CreditCardNumber", reader), + expr_date = GetDBString("ExpirationDate", reader) + }; + + + + invList.Add(new Invoice + { + invoiceId = int.Parse(GetDBString("invoiceid", reader)), + customerId = int.Parse(GetDBString("customerid", reader)), + invoiceDate = GetSqlDate("invoicedate", reader), + address = GetDBString("billingaddress", reader), + city = GetDBString("billingcity", reader), + state = GetDBString("billingstate", reader), + country = GetDBString("billingcountry", reader), + post = GetDBString("billingpostalcode", reader), + total = float.Parse(GetDBString("total", reader)), + payment = LoadPayment + /*payment = new Payment + { + PayId = int.Parse(GetDBString("payId", reader)), + is_default = int.Parse(GetDBString("IsDefault", reader)), + token = Correct_Token, + email = GetDBString("GoogleEmail", reader), + cardnum = GetDBString("CreditCardNumber", reader), + expr_date = GetDBString("ExpirationDate", reader) + }*/ + }); + } } @@ -1109,4 +1190,5 @@ namespace TeamDBAwesome.SqlService } } } // ADL: I added this ending paren. -} \ No newline at end of file +} + \ No newline at end of file