Skip to content

Commit

Permalink
built a test API
Browse files Browse the repository at this point in the history
new user isn't working yet, but it will be
  • Loading branch information
Jeremy Mill committed Nov 8, 2015
1 parent 79fa604 commit 9418def
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
51 changes: 51 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.Models;
using TeamDBAwesome.SqlService;

namespace TeamDBAwesome.Controllers
{
public class TestController : ApiController
{
// 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 = 0;
test.Email = "test@test.com";
test.Fax = "9109153999";
test.FName = "test";
test.LName = "test";
test.PersonID = 0;
test.Phone = "9109153999";
test.Post = "06066";
test.State = "CT";
test.SupportRepId = 0;

//make an instance of the sql controller
MySqlService sqlS = new MySqlService();
//try and add the new user
int ID = sqlS.AddNewUser(test);



//return an OK with the int of the new user
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(ID.ToString());
return response;


}


}
}
8 changes: 4 additions & 4 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void Init_Connection()
database = "chinook";
uid = "root";
//changeme
password = "a_password";
password = "";

string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

Expand Down Expand Up @@ -71,7 +71,7 @@ private bool CloseConnection()
}
}

public bool AddNewUser(Customer newCust)
public int AddNewUser(Customer newCust)
{
bool open = this.OpenConnection();

Expand Down Expand Up @@ -109,11 +109,11 @@ public bool AddNewUser(Customer newCust)
//close the connection
this.CloseConnection();

return true;
return int.Parse(newPersonID);
}
else
{
return false;
return 0;
}


Expand Down
2 changes: 2 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.9.8\lib\net45\MySql.Data.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -164,6 +165,7 @@
<Compile Include="Controllers\GetCustomerController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\NewCustomerController.cs" />
<Compile Include="Controllers\TestController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
Expand Down

0 comments on commit 9418def

Please sign in to comment.