Skip to content
Permalink
Browse files

more API's

  • Loading branch information
Jeremy Mill
Jeremy Mill committed Dec 8, 2015
1 parent 85976a1 commit 032f9accf74e0783490ef26006a156d5695d18a9
@@ -0,0 +1,23 @@
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 AddAlbumController : ApiController
{
public HttpResponseMessage Post([FromBody] Album album)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);
MySqlService sql = new MySqlService();
int newAlbum = sql.addAlbum(album);
message.Content = new StringContent(newAlbum.ToString());
return message;
}
}
}
@@ -0,0 +1,23 @@
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 AddArtistController : ApiController
{
public HttpResponseMessage Post([FromBody] Artist artist)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);
MySqlService sql = new MySqlService();
int newArtist = sql.AddArtist(artist);
message.Content = new StringContent(newArtist.ToString());
return message;
}
}
}
@@ -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 AddTrackController : ApiController
{
public HttpResponseMessage Post([FromBody]Track track)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);

MySqlService sql = new MySqlService();
int response = sql.AddTrack(track);

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

return message;

}
}
}
@@ -9,6 +9,6 @@ public class Album
{
public int AlbumId { get; set; }
public string Title { get; set; }
public int ArtistId { get; set; }
public string Artist { get; set; }
}
}
@@ -142,6 +142,130 @@ public int AddNewUser(Customer newCust)

}

public int AddTrack(Track track)
{
bool open = this.OpenConnection();
if(open == true)
{
string lastTackQuery = "select TrackId from track order by trackid desc limit 1";
MySqlCommand cmd = new MySqlCommand(lastTackQuery, SqlConn);
int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1;

string albumAndArtistQuery = "select AlbumId,ArtistID from album left join artist on album.artistid = artist.artistid " +
"where Title = " + track.AlbumTitle + " and Name = " + track.artist;
cmd = new MySqlCommand(albumAndArtistQuery, SqlConn);
MySqlDataReader reader = cmd.ExecuteReader();
string albumidstring = "", artistidstring = "";
int artistid = 0, albumid = 0;
while (reader.Read())
{
albumidstring = (GetDBString("AlbumID", reader));
if (String.IsNullOrEmpty(albumidstring))
{
albumid = 0;
}
else { albumid = int.Parse(albumidstring); }

artistidstring = GetDBString("ArtistID", reader);
if(String.IsNullOrEmpty(artistidstring)) { artistid = 0; }
else { artistid = int.Parse(artistidstring); }
}
reader.Close();

int mediatypeid = 0;
string mediatypeQuery = "select MediaTypeId from mediatype where Name = " + track.MediaType;
cmd = new MySqlCommand(mediatypeQuery, SqlConn);
string mediaTypeIdString = cmd.ExecuteScalar() + "";
if(String.IsNullOrEmpty(mediaTypeIdString))
{
return 0;
}
else
{
mediatypeid = int.Parse(mediaTypeIdString);
}

int genreId=0;
string genreIdQuery = "select mediatypeid from mediatype where Name = " + track.MediaType;
cmd = new MySqlCommand(genreIdQuery, SqlConn);
string genreIdString = cmd.ExecuteScalar() + "";
if (String.IsNullOrEmpty(genreIdString))
{
return 0;
}
else
{
genreId = int.Parse(genreIdString);
}


if (artistid == 0 || albumid == 0)
{
return 0;
}

string insert = "insert into track(TrackId,Name,AlbumId,MediaTypeId,GenreId,Composer,Milliseconds,Bytes,UnitPrice) "
+ "VALUES (" + nextNum + ",\"" + track.TrackName + "\"," + albumid + "," + mediatypeid + "," + genreId + ",\"" + track.Composer +
"\"," + track.Milliseconds + "," + track.Bytes + "," + track.UnitPrice + ")";
cmd = new MySqlCommand(insert, SqlConn);
cmd.ExecuteNonQuery();
return nextNum;
}
else
{
return 0;
}
}

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

string insert = "insert into artist(ArtistId,Name) VALUES (" + nextNum + ",\"" + artist.Name + "\")";
cmd = new MySqlCommand(insert, SqlConn);
cmd.ExecuteNonQuery();

return nextNum;
}
else
{
return 0;
}
}

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

int artistId = 0;
string getArtistIdQuery = "select ArtistId from artist where name = " + album.Artist;
cmd = new MySqlCommand(getArtistIdQuery, SqlConn);
string idString = cmd.ExecuteScalar() + "";
if(String.IsNullOrEmpty(idString)) { return 0; }
else { artistId = int.Parse(idString); }

string insert = "insert into album(AlbumId,Title,ArtistId) VALUES (" + nextNum + ",\"" + album.Title + "\"," + idString + ")";
cmd = new MySqlCommand(insert, SqlConn);
cmd.ExecuteNonQuery();

return nextNum;
}
else
{
return 0;
}
}

public int addToPlaylist(int trackid, int playlistid)
{
bool connect = this.OpenConnection();
@@ -163,9 +163,12 @@
<Compile Include="Areas\HelpPage\SampleGeneration\SampleDirection.cs" />
<Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AddAlbumController.cs" />
<Compile Include="Controllers\AddArtistController.cs" />
<Compile Include="Controllers\AddCustomPlaylistController.cs" />
<Compile Include="Controllers\AddPaymentController.cs" />
<Compile Include="Controllers\AddPlaylistController.cs" />
<Compile Include="Controllers\AddTrackController.cs" />
<Compile Include="Controllers\AddTrackCustomPlaylistController.cs" />
<Compile Include="Controllers\AddTrackOrderController.cs" />
<Compile Include="Controllers\AddTrackPlaylistController.cs" />

0 comments on commit 032f9ac

Please sign in to comment.
You can’t perform that action at this time.