Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
get payment is up
  • Loading branch information
Jeremy Mill committed Dec 2, 2015
1 parent 57d7765 commit fa53478
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 10 deletions.
30 changes: 30 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/GetPaymentController.cs
@@ -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 GetPaymentController : ApiController
{
public HttpResponseMessage Get(int CustomerID)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();

List<Payment> payList = sql.GetPayTypes(CustomerID);

string serialzed = JsonConvert.SerializeObject(payList);

message.Content = new StringContent(serialzed);

return message;
}
}
}
13 changes: 4 additions & 9 deletions TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
Expand Up @@ -15,18 +15,13 @@ namespace TeamDBAwesome.Controllers
// GET: api/Test
public HttpResponseMessage Get()
{
Payment test = new Payment
{
CustomerId = 7,
Type = "GP",
token = "54321",
email = "fuck@fuck.com",
is_default = 1
};


MySqlService sqlS = new MySqlService();

sqlS.AddPayment(test);
sqlS.GetPayTypes(7);



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

Expand Down
1 change: 1 addition & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/Payment.cs
Expand Up @@ -15,5 +15,6 @@ namespace TeamDBAwesome.Models
// needs to be in yyyy-mm-dd format
public string expr_date { get; set; }
public int is_default { get; set; }
public int PayId { get; set; }
}
}
79 changes: 79 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Expand Up @@ -43,6 +43,10 @@ namespace TeamDBAwesome.SqlService
return Reader[SqlFieldName].Equals(DBNull.Value) ? String.Empty : Reader.GetString(SqlFieldName);
}

private DateTime GetSqlDate(string SqlFieldName, MySqlDataReader Reader)
{
return new DateTime();
}
/// <summary>
/// opens a connection to the DB
/// </summary>
Expand Down Expand Up @@ -138,6 +142,11 @@ namespace TeamDBAwesome.SqlService

}

/// <summary>
/// adds a payment type to the database
/// </summary>
/// <param name="payment">an instance of the Payment Model</param>
/// <returns>0 on success, 1 on error</returns>
public int AddPayment(Payment payment)
{
bool open = this.OpenConnection();
Expand Down Expand Up @@ -401,6 +410,76 @@ namespace TeamDBAwesome.SqlService
}
}

public List<Payment> GetPayTypes(int customerId)
{
List<Payment> payList = new List<Payment>();
bool open = this.OpenConnection();

if(open == true)
{
string query = "select payment.PayId as PayId,payment.CustomerId as CustomerID, applepay.ApplePayToken as AppleToken, "
+ "googlepay.GoogleToken as GoogleToken, googlepay.GoogleEmail as GoogleEmail, creditcard.CreditCardNumber as CardNum, "
+ "creditcard.ExpirationDate as ExprDate, payment.IsDefault as IsDefault "
+ "from chinook.payment left join googlepay on payment.PayId = googlepay.PayId "
+ "left join applepay on payment.PayId = applepay.PayId left join creditcard on creditcard.PayId = payment.PayId "
+ "where CustomerId = " + customerId;

MySqlCommand command = new MySqlCommand(query, SqlConn);
MySqlDataReader reader = command.ExecuteReader();

Payment newPayment;

while (reader.Read())
{
newPayment = new Payment();

//change token, type with logic
newPayment.CustomerId = int.Parse(GetDBString("CustomerID", reader));
newPayment.PayId = int.Parse(GetDBString("PayId", reader));
string is_default = GetDBString("IsDefault", reader);
string appleToken = GetDBString("AppleToken", reader);
string googleToken = GetDBString("GoogleToken", reader);
string googleEmail = GetDBString("GoogleEmail", reader);
string cardNum = GetDBString("CardNum", reader);
string exprDate = GetDBString("ExprDate", reader);

if(is_default == "True")
{
newPayment.is_default = 1;
}
else
{
newPayment.is_default = 0;
}

if (cardNum != "")
{
newPayment.Type = "CC";
newPayment.cardnum = cardNum;
newPayment.expr_date = exprDate;
}
else if (googleToken != "")
{
newPayment.Type = "GP";
newPayment.email = googleEmail;
newPayment.token = googleToken;
}
else if (appleToken != "")
{
newPayment.Type = "AP";
newPayment.token = appleToken;
}

payList.Add(newPayment);
}

}


return payList;
}


/// <summary>
/// Gets a track from the DB
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Expand Up @@ -165,6 +165,7 @@
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AddPaymentController.cs" />
<Compile Include="Controllers\GetCustomerController.cs" />
<Compile Include="Controllers\GetPaymentController.cs" />
<Compile Include="Controllers\GetTrackController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\NewCustomerController.cs" />
Expand Down
3 changes: 2 additions & 1 deletion TeamDBAwesome/TeamDBAwesome/js/HolderService.js
Expand Up @@ -50,7 +50,8 @@
//YYYY-MM-DD
expr_date: null,
//is_default is 0 for false, 1 for true
is_default: null
is_default: null,
PayId: null
}


Expand Down
Binary file modified chinookmodel.mwb
Binary file not shown.
Binary file modified chinookmodel.mwb.bak
Binary file not shown.

0 comments on commit fa53478

Please sign in to comment.