Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more APIs
  • Loading branch information
Jeremy Mill committed Dec 6, 2015
1 parent 94b4892 commit 83249db
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
26 changes: 26 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/AddPlaylistController.cs
@@ -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 AddPlaylistController : ApiController
{
public HttpResponseMessage Get(string playlistname)
{
MySqlService dbService = new MySqlService();

int newID = dbService.NewPlaylist(playlistname);

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

}
}
}
27 changes: 27 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/DropPlaylistController.cs
@@ -0,0 +1,27 @@
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 DropPlaylistController : ApiController
{
public HttpResponseMessage Get(int PlaylistID)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();

int succ = sql.DropPlaylist(PlaylistID);

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

return message;
}
}
}
49 changes: 49 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Expand Up @@ -491,6 +491,39 @@ namespace TeamDBAwesome.SqlService
}
}

public int NewPlaylist(string playlistname)
{
bool open = this.OpenConnection();
if (open == true)
{
string lastRowQuery = "select PlaylistId from playlist order by PlaylistId desc limit 1";
MySqlCommand command = new MySqlCommand(lastRowQuery, SqlConn);
int lastId = int.Parse(command.ExecuteScalar() + "");
int nextId = lastId + 1;


string newInsert = "insert into playlist(Name,PlaylistId) VALUES(\"" + playlistname + "\"," + nextId + ")";

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


try
{
return nextId;
}
catch (Exception e)
{
return 0;
}

}
else
{
return 0;
}
}

public int DropCustomPlaylist(int pid)
{
bool open = this.OpenConnection();
Expand All @@ -507,6 +540,22 @@ namespace TeamDBAwesome.SqlService
}
}

public int DropPlaylist(int pid)
{
bool open = this.OpenConnection();
if (open == true)
{
string dropCommand = "Delete from playlist 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
2 changes: 2 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Expand Up @@ -165,7 +165,9 @@
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AddCustomPlaylistController.cs" />
<Compile Include="Controllers\AddPaymentController.cs" />
<Compile Include="Controllers\AddPlaylistController.cs" />
<Compile Include="Controllers\DropCustomPlaylistController.cs" />
<Compile Include="Controllers\DropPlaylistController.cs" />
<Compile Include="Controllers\GetCustomerController.cs" />
<Compile Include="Controllers\GetCustomPlaylistController.cs" />
<Compile Include="Controllers\GetCustomPlaylistsController.cs" />
Expand Down

0 comments on commit 83249db

Please sign in to comment.