diff --git a/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs b/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
index 02ab332..142e66c 100644
--- a/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
+++ b/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
@@ -15,18 +15,18 @@ public class TestController : ApiController
// GET: api/Test
public HttpResponseMessage Get()
{
- /*//make a test customer
+ //make a test customer
Customer test = new Customer();
test.Address = "test";
test.City = "test";
test.Company = "test";
test.Country = "test";
- test.CustomerID = 0;
+ test.CustomerID = 10;
test.Email = "test@test.com";
test.Fax = "9109153999";
test.FName = "test";
test.LName = "test";
- test.PersonID = 0;
+ test.PersonID = 10;
test.Phone = "9109153999";
test.Post = "06066";
test.State = "CT";
@@ -36,29 +36,18 @@ public HttpResponseMessage Get()
MySqlService sqlS = new MySqlService();
//try and add the new user
//int ID = sqlS.AddNewUser(test);
- int ID = 0;
+ //int ID = 0;
- Customer customer = sqlS.GetCustomer(3);*/
+ sqlS.UpdateCustomer(test);
- Search search = new Search
- {
- Media = "test",
- Album = "test",
- Artist = "test",
- Track = "test",
- Composer = "test",
- Genre = "test"
- };
+ //Customer customer = sqlS.GetCustomer(3);
- MySqlService service = new MySqlService();
-
- SearchResult result = service.Search(search);
- string serialized = JsonConvert.SerializeObject(result);
+
//return an OK with the int of the new user
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
- response.Content = new StringContent(serialized);
+ //response.Content = new StringContent(serialized);
return response;
diff --git a/TeamDBAwesome/TeamDBAwesome/Controllers/UpdateUserController.cs b/TeamDBAwesome/TeamDBAwesome/Controllers/UpdateUserController.cs
new file mode 100644
index 0000000..9ebe863
--- /dev/null
+++ b/TeamDBAwesome/TeamDBAwesome/Controllers/UpdateUserController.cs
@@ -0,0 +1,34 @@
+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 UpdateUserController : ApiController
+ {
+ public HttpResponseMessage Post([FromBody] Customer customer)
+ {
+ MySqlService dbService = new MySqlService();
+
+ if (ModelState.IsValid == true)
+ {
+ dbService.UpdateCustomer(customer);
+ HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
+ response.Content = new StringContent("0");
+ return response;
+ }
+ else
+ {
+ HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.BadRequest);
+ response.Content = new StringContent("Malformed Data");
+ return response;
+ }
+
+ }
+ }
+}
diff --git a/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs b/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
index a032b10..3bdecec 100644
--- a/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
+++ b/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
@@ -133,6 +133,40 @@ public int AddNewUser(Customer newCust)
}
+ public int UpdateCustomer(Customer customer)
+ {
+ string update_person = "Update person SET FirstName=\'" + customer.FName + "\', LastName=\'" + customer.LName +
+ "\', Address=\'" + customer.Address + "\', City=\'" + customer.City + "\', State=\'" + customer.State +
+ "\', Country=\'" + customer.Country + "\', PostalCode=\'" + customer.Post + "\', Phone=\'" +
+ customer.Phone + "\', Fax=\'" + customer.Fax + "\', Email=\'" + customer.Email + "\' WHERE PersonId=\'" +
+ customer.PersonID + "\'";
+
+ string update_customer = "Update customer set Company=\'" + customer.Company + "\', SupportRepID=\'" +
+ customer.SupportRepId + "\' WHERE CustomerId =\'" + customer.CustomerID + "\'";
+
+ Debug.WriteLine(update_person);
+ Debug.WriteLine(update_customer);
+
+ bool open = this.OpenConnection();
+
+ if (open == true)
+ {
+ MySqlCommand command = new MySqlCommand(update_person, SqlConn);
+ command.ExecuteNonQuery();
+
+ command = new MySqlCommand(update_customer, SqlConn);
+ command.ExecuteNonQuery();
+
+ this.CloseConnection();
+
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
public Customer GetCustomer(int PersonID)
{
bool open = this.OpenConnection();
@@ -178,7 +212,7 @@ public Customer GetCustomer(int PersonID)
public SearchResult Search(Search search)
{
bool open = this.OpenConnection();
- SearchResult result = new SearchResult();
+ SearchResult searchresult = new SearchResult();
if(open == true)
{
@@ -196,7 +230,7 @@ public SearchResult Search(Search search)
queries.Add("Genre", "select * from chinook.genre where name like \'%" + search.Genre + "%\' ");
//declare theresult and init it
- SearchResult searchresult = new SearchResult();
+ //SearchResult searchresult = new SearchResult();
//declare the cmd and the reader
//MySqlCommand cmd;
@@ -280,14 +314,15 @@ public SearchResult Search(Search search)
reader.Close();
}
+ this.CloseConnection();
- result = searchresult;
- return result;
+ //result = searchresult;
+ return searchresult;
}
else
{
- return result;
+ return searchresult;
}
}
}
diff --git a/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj b/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
index 31d0acc..6179ad8 100644
--- a/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
+++ b/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
@@ -168,6 +168,7 @@
+
Global.asax