diff --git a/TeamDBAwesome/TeamDBAwesome/Controllers/AddCustomPlaylistController.cs b/TeamDBAwesome/TeamDBAwesome/Controllers/AddCustomPlaylistController.cs new file mode 100644 index 0000000..69886d0 --- /dev/null +++ b/TeamDBAwesome/TeamDBAwesome/Controllers/AddCustomPlaylistController.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 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; + + } + } +} diff --git a/TeamDBAwesome/TeamDBAwesome/Controllers/DropCustomPlaylistController.cs b/TeamDBAwesome/TeamDBAwesome/Controllers/DropCustomPlaylistController.cs new file mode 100644 index 0000000..b574800 --- /dev/null +++ b/TeamDBAwesome/TeamDBAwesome/Controllers/DropCustomPlaylistController.cs @@ -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; + } + } +} diff --git a/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs b/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs index ed992c8..023e9cf 100644 --- a/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs +++ b/TeamDBAwesome/TeamDBAwesome/Controllers/TestController.cs @@ -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); diff --git a/TeamDBAwesome/TeamDBAwesome/Models/CustomPlaylistId.cs b/TeamDBAwesome/TeamDBAwesome/Models/CustomPlaylistId.cs new file mode 100644 index 0000000..38f77ff --- /dev/null +++ b/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; } + } +} \ No newline at end of file diff --git a/TeamDBAwesome/TeamDBAwesome/Models/Track.cs b/TeamDBAwesome/TeamDBAwesome/Models/Track.cs index 5b6f152..10b9729 100644 --- a/TeamDBAwesome/TeamDBAwesome/Models/Track.cs +++ b/TeamDBAwesome/TeamDBAwesome/Models/Track.cs @@ -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; } } } \ No newline at end of file diff --git a/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs b/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs index e2b5a5d..d984d37 100644 --- a/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs +++ b/TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs @@ -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 GetPayTypes(int customerId) { List payList = new List(); diff --git a/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj b/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj index 4e9d7bb..848738c 100644 --- a/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj +++ b/TeamDBAwesome/TeamDBAwesome/TeamDBAwesome.csproj @@ -163,7 +163,9 @@ + + @@ -182,6 +184,7 @@ + diff --git a/TeamDBAwesome/TeamDBAwesome/js/HolderService.js b/TeamDBAwesome/TeamDBAwesome/js/HolderService.js index 2f9a6f0..f69c1af 100644 --- a/TeamDBAwesome/TeamDBAwesome/js/HolderService.js +++ b/TeamDBAwesome/TeamDBAwesome/js/HolderService.js @@ -30,6 +30,7 @@ Milliseconds: null, Bytes: null, UnitPrice: null, + artist: null }; var Blank_Payment = { @@ -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 @@ -65,6 +71,9 @@ }, getBlankPayment: function () { return Blank_Payment; + }, + getBlankCustomPlaylist: function () { + return Blank_CustomPlaylistId; } };