Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
two more APIs
  • Loading branch information
Jeremy Mill committed Dec 8, 2015
1 parent 9da7ec1 commit 5c6a5e0
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
22 changes: 22 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/AddGenreController.cs
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.SqlService;

namespace TeamDBAwesome.Controllers
{
public class AddGenreController : ApiController
{
public HttpResponseMessage Get(string GenreName)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);
MySqlService sql = new MySqlService();
int newArtist = sql.AddGenre(GenreName);
message.Content = new StringContent(newArtist.ToString());
return message;
}
}
}
22 changes: 22 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/Controllers/AddMediaTypeController.cs
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.SqlService;

namespace TeamDBAwesome.Controllers
{
public class AddMediaTypeController : ApiController
{
public HttpResponseMessage Get(string TypeName)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);
MySqlService sql = new MySqlService();
int newArtist = sql.AddMediaType(TypeName);
message.Content = new StringContent(newArtist.ToString());
return message;
}
}
}
36 changes: 36 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Expand Up @@ -238,6 +238,42 @@ namespace TeamDBAwesome.SqlService
} }
} }


public int AddGenre(string name)
{
bool open = this.OpenConnection();
if(open == true)
{
string lastArtistQuery = "select GenreId from genre order by GenreId desc limit 1";
MySqlCommand cmd = new MySqlCommand(lastArtistQuery, SqlConn);
int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1;

string insertGenre = "insert into Genre(GenreId,Name) VALUES (" + nextNum + ",\"" + name + "\")";
return nextNum;
}
else
{
return 0;
}
}

public int AddMediaType(string name)
{
bool open = this.OpenConnection();
if (open == true)
{
string lastArtistQuery = "select MediaTypeId from MediaType order by MediaTypeId desc limit 1";
MySqlCommand cmd = new MySqlCommand(lastArtistQuery, SqlConn);
int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1;

string insertGenre = "insert into MediaType(MediaTypeId,Name) VALUES (" + nextNum + ",\"" + name + "\")";
return nextNum;
}
else
{
return 0;
}
}

public int addAlbum(Album album) public int addAlbum(Album album)
{ {
bool open = this.OpenConnection(); bool open = this.OpenConnection();
Expand Down
2 changes: 2 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj
Expand Up @@ -166,6 +166,8 @@
<Compile Include="Controllers\AddAlbumController.cs" /> <Compile Include="Controllers\AddAlbumController.cs" />
<Compile Include="Controllers\AddArtistController.cs" /> <Compile Include="Controllers\AddArtistController.cs" />
<Compile Include="Controllers\AddCustomPlaylistController.cs" /> <Compile Include="Controllers\AddCustomPlaylistController.cs" />
<Compile Include="Controllers\AddGenreController.cs" />
<Compile Include="Controllers\AddMediaTypeController.cs" />
<Compile Include="Controllers\AddPaymentController.cs" /> <Compile Include="Controllers\AddPaymentController.cs" />
<Compile Include="Controllers\AddPlaylistController.cs" /> <Compile Include="Controllers\AddPlaylistController.cs" />
<Compile Include="Controllers\AddTrackController.cs" /> <Compile Include="Controllers\AddTrackController.cs" />
Expand Down

0 comments on commit 5c6a5e0

Please sign in to comment.