Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more API's
  • Loading branch information
Jeremy Mill committed Dec 6, 2015
1 parent 739e072 commit 94b4892
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 4 deletions.
@@ -0,0 +1,26 @@
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 AddCustomPlaylistController : ApiController
{
public HttpResponseMessage Post([FromBody] CustomPlaylistId custom)
{
MySqlService dbService = new MySqlService();

int newID = dbService.NewCustomPlaylist(custom);

HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(newID.ToString());
return response;

}
}
}
@@ -0,0 +1,28 @@
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 DropCustomPlaylistController : ApiController
{
// GET: api/GetCustomer
public HttpResponseMessage Get(int PlaylistID)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();

int succ = sql.DropCustomPlaylist(PlaylistID);

message.Content = new StringContent(succ.ToString());

return message;
}
}
}
8 changes: 6 additions & 2 deletions TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs
Expand Up @@ -15,11 +15,15 @@ namespace TeamDBAwesome.Controllers
// GET: api/Test
public HttpResponseMessage Get()
{

CustomPlaylistId newid = new CustomPlaylistId
{
Name = "apitest",
CustomerId = 16
};

MySqlService sqlS = new MySqlService();

sqlS.GetPayTypes(7);
sqlS.NewCustomPlaylist(newid);



Expand Down
13 changes: 13 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Models/CustomPlaylistId.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class CustomPlaylistId
{
public int CustomerId { get; set; }
public string Name { get; set; }
}
}
3 changes: 2 additions & 1 deletion TeamDBAwesome/TeamDBAwesome/Models/Track.cs
Expand Up @@ -15,6 +15,7 @@ namespace TeamDBAwesome.Models
public string Composer { get; set; }
public int Milliseconds { get; set; }
public int Bytes { get; set; }
public float UnitPrice { get; set; }
public float UnitPrice { get; set; }
public string artist { get; set; }
}
}
47 changes: 47 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Expand Up @@ -460,6 +460,53 @@ namespace TeamDBAwesome.SqlService
}
}

public int NewCustomPlaylist(CustomPlaylistId playlist)
{
bool open = this.OpenConnection();
if(open == true)
{
string newInsert = "insert into myplaylist(Name,CustomerId) VALUES(\"" + playlist.Name + "\"," + playlist.CustomerId + ")";

MySqlCommand command = new MySqlCommand(newInsert, SqlConn);
command.ExecuteNonQuery();

//now we need to get the primary key from that recent update
string pk_query = "SELECT LAST_INSERT_ID()";
command = new MySqlCommand(pk_query, SqlConn);
string newCustomPlaylistId = command.ExecuteScalar() + "";

try
{
return int.Parse(newCustomPlaylistId);
}
catch(Exception e)
{
return 0;
}

}
else
{
return 0;
}
}

public int DropCustomPlaylist(int pid)
{
bool open = this.OpenConnection();
if(open == true)
{
string dropCommand = "Delete from myplaylist where PlaylistId = " + pid;
MySqlCommand command = new MySqlCommand(dropCommand, SqlConn);
command.ExecuteNonQuery();
return 1;
}
else
{
return 0;
}
}

public List<Payment> GetPayTypes(int customerId)
{
List<Payment> payList = new List<Payment>();
Expand Down
3 changes: 3 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Expand Up @@ -163,7 +163,9 @@
<Compile Include="Areas\HelpPage\SampleGeneration\SampleDirection.cs" />
<Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AddCustomPlaylistController.cs" />
<Compile Include="Controllers\AddPaymentController.cs" />
<Compile Include="Controllers\DropCustomPlaylistController.cs" />
<Compile Include="Controllers\GetCustomerController.cs" />
<Compile Include="Controllers\GetCustomPlaylistController.cs" />
<Compile Include="Controllers\GetCustomPlaylistsController.cs" />
Expand All @@ -182,6 +184,7 @@
<Compile Include="Models\Album.cs" />
<Compile Include="Models\Artist.cs" />
<Compile Include="Models\Customer.cs" />
<Compile Include="Models\CustomPlaylistId.cs" />
<Compile Include="Models\Genre.cs" />
<Compile Include="Models\Media.cs" />
<Compile Include="Models\Payment.cs" />
Expand Down
11 changes: 10 additions & 1 deletion TeamDBAwesome/TeamDBAwesome/js/HolderService.js
Expand Up @@ -30,6 +30,7 @@
Milliseconds: null,
Bytes: null,
UnitPrice: null,
artist: null
};

var Blank_Payment = {
Expand All @@ -52,7 +53,12 @@
//is_default is 0 for false, 1 for true
is_default: null,
PayId: null
}
};

var Blank_CustomPlaylistId = {
CustomerId: null,
Name: null
};


//create the accessor for it
Expand All @@ -65,6 +71,9 @@
},
getBlankPayment: function () {
return Blank_Payment;
},
getBlankCustomPlaylist: function () {
return Blank_CustomPlaylistId;
}
};

Expand Down

0 comments on commit 94b4892

Please sign in to comment.