Skip to content
Permalink
Browse files

added get all invoices

  • Loading branch information
Jeremy Mill
Jeremy Mill committed Dec 10, 2015
1 parent adf00cf commit d65bc2d29ddda8d738b01d83939b6a4ad7b05e77
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.SqlService;
using TeamDBAwesome.Models;
using Newtonsoft.Json;

namespace TeamDBAwesome.Controllers
{
public class GetAllInvoicesController : ApiController
{
public HttpResponseMessage Get(int custId)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();

List<Invoice> invoiceList = sql.getAllInvoices();

string serialized = JsonConvert.SerializeObject(invoiceList);

message.Content = new StringContent(serialized);

return message;
}
}
}
@@ -567,6 +567,100 @@ public List<Invoice> getInvoices(int custId)
return invList;
}

public List<Invoice> getAllInvoices()
{
List<Invoice> invList = new List<Invoice>();
bool open = this.OpenConnection();
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, 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 ";

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);
IsDef = 0;
}

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)
}*/
});
}
}


return invList;
}

/// <summary>
/// adds a payment type to the database
/// </summary>
@@ -178,6 +178,7 @@
<Compile Include="Controllers\DropCustomPlaylistController.cs" />
<Compile Include="Controllers\DropPlaylistController.cs" />
<Compile Include="Controllers\GenerateInvoiceController.cs" />
<Compile Include="Controllers\GetAllInvoicesController.cs" />
<Compile Include="Controllers\GetCustomerController.cs" />
<Compile Include="Controllers\GetCustomerInvoiceController.cs" />
<Compile Include="Controllers\GetCustomerOrdersController.cs" />

0 comments on commit d65bc2d

Please sign in to comment.
You can’t perform that action at this time.