Skip to content

Commit

Permalink
Update User is good now
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Mill committed Nov 18, 2015
1 parent 872242a commit 1d0e7e0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 24 deletions.
27 changes: 8 additions & 19 deletions TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;

Expand Down
34 changes: 34 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/UpdateUserController.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
}
45 changes: 40 additions & 5 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<Compile Include="Controllers\NewCustomerController.cs" />
<Compile Include="Controllers\SearchController.cs" />
<Compile Include="Controllers\TestController.cs" />
<Compile Include="Controllers\UpdateUserController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
Expand Down

0 comments on commit 1d0e7e0

Please sign in to comment.