Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create new media functions work except for AddAlbum
  • Loading branch information
sec11008 committed Dec 9, 2015
1 parent d3faf96 commit 8d7ac36
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 19 deletions.
2 changes: 1 addition & 1 deletion TeamDBAwesome/TeamDBAwesome/Models/Track.cs
Expand Up @@ -9,7 +9,7 @@ namespace TeamDBAwesome.Models
{ {
public int TrackId { get; set; } public int TrackId { get; set; }
public string TrackName { get; set; } public string TrackName { get; set; }
public string AlbumTitle { get; set; } //Should this be album id to match the sql? public string AlbumTitle { get; set; }
public string MediaType { get; set; } public string MediaType { get; set; }
public string Genre { get; set; } public string Genre { get; set; }
public string Composer { get; set; } public string Composer { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/SqlService/MySqlService.cs
Expand Up @@ -248,6 +248,9 @@ namespace TeamDBAwesome.SqlService
int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1; int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1;


string insertGenre = "insert into Genre(GenreId,Name) VALUES (" + nextNum + ",\"" + name + "\")"; string insertGenre = "insert into Genre(GenreId,Name) VALUES (" + nextNum + ",\"" + name + "\")";
cmd = new MySqlCommand(insertGenre, SqlConn);
cmd.ExecuteNonQuery();

return nextNum; return nextNum;
} }
else else
Expand All @@ -266,6 +269,9 @@ namespace TeamDBAwesome.SqlService
int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1; int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1;


string insertGenre = "insert into MediaType(MediaTypeId,Name) VALUES (" + nextNum + ",\"" + name + "\")"; string insertGenre = "insert into MediaType(MediaTypeId,Name) VALUES (" + nextNum + ",\"" + name + "\")";
cmd = new MySqlCommand(insertGenre, SqlConn);
cmd.ExecuteNonQuery();

return nextNum; return nextNum;
} }
else else
Expand Down
19 changes: 19 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/app.js
Expand Up @@ -143,3 +143,22 @@ app.run(['$rootScope', '$state', '$stateParams','$http',
$rootScope.$stateParams = $stateParams; $rootScope.$stateParams = $stateParams;
$http.defaults.headers.common.Authentication = 'Basic Token'; $http.defaults.headers.common.Authentication = 'Basic Token';
}]); }]);

app.filter('formatTime', function() {
return function(milliseconds) {
var seconds = parseInt((milliseconds/1000)%60);
var minutes = parseInt((milliseconds/(100060))%60);
var hours = parseInt((milliseconds/(100060*60))%24);
var out = "";

minutes = (parseInt(minutes) + (60 * parseInt(hours)));
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;

out = minutes + ":" + seconds;


return out;
};

});
156 changes: 140 additions & 16 deletions TeamDBAwesome/TeamDBAwesome/js/adminController.js
Expand Up @@ -43,35 +43,159 @@ angular.module('routerApp').controller('adminController', function ($scope, $htt
}; };
$scope.toCreateAlbum = function () { $scope.toCreateAlbum = function () {
$scope.showMediaOptions = false; $scope.showMediaOptions = false;
$scope.showAlbumFields = true;

}; };
$scope.toCreateArtist = function () { $scope.toCreateArtist = function () {
$scope.showMediaOptions = false; $scope.showMediaOptions = false;
$scope.showArtistFields = true;
}; };
$scope.toCreateGenre = function () { $scope.toCreateGenre = function () {
$scope.showMediaOptions = false; $scope.showMediaOptions = false;
$scope.showGenreFields = true;
}; };
$scope.toCreateMediaType = function () { $scope.toCreateMediaType = function () {
$scope.showMediaOptions = false; $scope.showMediaOptions = false;
$scope.showMediaTypeFields = true;

}; };

$scope.createTrack = function (newTrack) {
var sub = HolderService.getBlankTrack();
if (newTrack.company == null) {
newTrack.company = null;
}
sub.TrackName = newTrack.trackName;
sub.artist = newTrack.artist;
sub.AlbumTitle = newTrack.albumTitle;
sub.MediaType = newTrack.mediaType;
sub.Genre = newTrack.genre;
sub.Composer = newTrack.composer;
sub.Milliseconds = newTrack.milliseconds;
sub.Bytes = newTrack.bytes;
sub.UnitPrice = newTrack.unitPrice;
console.log(sub);

var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddTrack",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created a track!';
console.log(response);
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
});
}

$scope.createArtist = function (newArtist) {
var sub = {
ArtistID: null,
Name: null
}
sub.Name = newArtist.artistName;
console.log(sub);

var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddArtist",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created an artist!';
console.log(response);
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
});
}

$scope.createAlbum = function (newAlbum) {
var sub = {
AlbumID: null,
Title: null,
Artist: null
}
sub.Title = newAlbum.albumName;
sub.Artist = newAlbum.artistName;
console.log(sub);

var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddAlbum",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created an album!';
console.log(response);
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
console.log(error);
console.log(error.ExceptionMessage);
console.log(error.ExeceptionType);
console.log(error.StackTrace);
});

}

$scope.createGenre = function (genreName) {
$http.get("http://localhost:50031/api/AddGenre?GenreName=" + genreName)
.success(function (response) {
$scope.messages = 'You created a genre!';
console.log(response);
alert($scope.messages);
})

}

$scope.createMediaType = function (mediaTypeName) {
$http.get("http://localhost:50031/api/AddMediaType?TypeName=" + mediaTypeName)
.success(function (response) {
$scope.messages = 'You created a media type!';
console.log(response);
alert($scope.messages);
})

}


//End New Media //End New Media


//CustomerDemographics //CustomerDemographics
$scope.custInfoGridOptions = { $scope.custInfoGridOptions = {
enableFiltering: true, enableFiltering: true,
columnDefs: [ columnDefs: [
{field: 'Fname', displayName: 'First Name'}, {field: 'Fname', displayName: 'First Name'},
{field: 'Lname', displayName: 'Last Name'}, {field: 'Lname', displayName: 'Last Name'},
{field: 'Address'}, {field: 'Address'},
{field: 'City'}, {field: 'City'},
{field: 'State'}, {field: 'State'},
{field: 'Post'}, {field: 'Post'},
{field: 'Country'}, {field: 'Country'},
{field: 'Phone'}, {field: 'Phone'},
{field: 'Fax'}, {field: 'Fax'},
{field: 'Email'}, {field: 'Email'},
{field: 'Company'} {field: 'Company'}
] ]
} }


//End Customer Demographics //End Customer Demographics


Expand All @@ -89,7 +213,7 @@ angular.module('routerApp').controller('adminController', function ($scope, $htt
}) })
} }
$scope.getPlaylists(); $scope.getPlaylists();
$state.go($state.current, {}, { reload: true }); $state.reload();
} }


$scope.toEdit = function (playlistID) { $scope.toEdit = function (playlistID) {
Expand All @@ -112,7 +236,7 @@ angular.module('routerApp').controller('adminController', function ($scope, $htt
$scope.dropPlaylist(playlistID); $scope.dropPlaylist(playlistID);
} }
$scope.getPlaylists(); $scope.getPlaylists();
$state.go($state.current, {}, { reload: true }); $state.reload();
} }


$scope.dropPlaylist = function (playlistID) { $scope.dropPlaylist = function (playlistID) {
Expand Down
7 changes: 5 additions & 2 deletions TeamDBAwesome/TeamDBAwesome/pages/admin-playlist-manager.html
Expand Up @@ -3,6 +3,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
</head> </head>
<div ng-controller="adminController"> <div ng-controller="adminController">
<!--List of playlists-->
<div ng-hide="editing" ng-init="getPlaylists();"> <div ng-hide="editing" ng-init="getPlaylists();">
<a ng-click="addPlaylist();">Create New Playlist</a> <a ng-click="addPlaylist();">Create New Playlist</a>
<table> <table>
Expand All @@ -20,9 +21,11 @@
</tr> </tr>
</table> </table>
</div> </div>
<!--Edit Playlist view-->
<div ng-show="editing"> <div ng-show="editing">
<a ng-click="editing=false; addingTrack=false;" ui-sref="admin-playlist-manager" class="btn btn-lg btn-primary center-block">Back</a> <a ng-click="editing=false; addingTrack=false;" ui-sref="admin-playlist-manager" class="btn btn-lg btn-primary center-block">Back</a>
<a ng-hide="addingTrack" ng-click="addingTrack=true;" ui-sref="admin-playlist-manager" class="btn btn-lg btn-primary center-block">Add a track</a> <a ng-hide="addingTrack" ng-click="addingTrack=true;" ui-sref="admin-playlist-manager" class="btn btn-lg btn-primary center-block">Add a track</a>
<!--Search for adding tracks to playlist-->
<div ng-show="addingTrack"> <div ng-show="addingTrack">
<form name="myForm"> <form name="myForm">
<table> <table>
Expand Down Expand Up @@ -54,7 +57,7 @@
<br /> <br />
<br /> <br />
</div> </div>

<!--List of tracks in playlist-->
<table> <table>
<tr> <tr>
<td>Track Id</td> <td>Track Id</td>
Expand All @@ -68,7 +71,7 @@
<td>{{ track.TrackId }}</td> <td>{{ track.TrackId }}</td>
<td>{{ track.TrackName }}</td> <td>{{ track.TrackName }}</td>
<td>{{ track.artist }}</td> <td>{{ track.artist }}</td>
<td>{{ track.Milliseconds }}</td> <td>{{ track.Milliseconds | formatTime }}</td>
<td>{{ track.UnitPrice | currency }}</td> <td>{{ track.UnitPrice | currency }}</td>
<td><a ng-click="deleteTrack(track.TrackId)">Delete</a></td> <td><a ng-click="deleteTrack(track.TrackId)">Delete</a></td>
</tr> </tr>
Expand Down
63 changes: 63 additions & 0 deletions TeamDBAwesome/TeamDBAwesome/pages/new-media.html
Expand Up @@ -16,6 +16,11 @@
<input type="text" name="trackName" id="trackName" class="form-control" ng-model="track.trackName" required /> <input type="text" name="trackName" id="trackName" class="form-control" ng-model="track.trackName" required />
<span ng-show="form.trackName.$dirty && form.trackName.$error.required" class="help-block">Track name is required</span> <span ng-show="form.trackName.$dirty && form.trackName.$error.required" class="help-block">Track name is required</span>
</div> </div>
<div class="form-group" ng-class="{ 'has-error': form.artist.$dirty && form.artist.$error.required }">
<label for="artist">Artist</label>
<input type="text" name="artist" id="artist" class="form-control" ng-model="track.artist" required />
<span ng-show="form.artist.$dirty && form.artist.$error.required" class="help-block">Artist is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.albumTitle.$dirty && form.albumTitle.$error.required }"> <div class="form-group" ng-class="{ 'has-error': form.albumTitle.$dirty && form.albumTitle.$error.required }">
<label for="albumTitle">Album Title</label> <label for="albumTitle">Album Title</label>
<input type="text" name="albumTitle" id="albumTitle" class="form-control" ng-model="track.albumTitle"/> <input type="text" name="albumTitle" id="albumTitle" class="form-control" ng-model="track.albumTitle"/>
Expand Down Expand Up @@ -50,11 +55,69 @@
<input type="text" name="unitPrice" id="unitPrice" class="form-control" ng-model="track.unitPrice" required /> <input type="text" name="unitPrice" id="unitPrice" class="form-control" ng-model="track.unitPrice" required />
<span ng-show="form.unitPrice.$dirty && form.unitPrice.$error.required" class="help-block">Unit Price is required</span> <span ng-show="form.unitPrice.$dirty && form.unitPrice.$error.required" class="help-block">Unit Price is required</span>
</div> </div>

<div class="form-actions"> <div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createTrack(track)" class="btn btn-primary">Submit</button> <button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createTrack(track)" class="btn btn-primary">Submit</button>
</div> </div>


</form> </form>
<form ng-show="showAlbumFields">
<div class="form-group" ng-class="{ 'has-error': form.albumName.$dirty && form.albumName.$error.required }">
<label for="albumName">Album name</label>
<input type="text" name="albumName" id="albumName" class="form-control" ng-model="album.albumName" required />
<span ng-show="form.albumName.$dirty && form.albumName.$error.required" class="help-block">Album name is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.artistName.$dirty && form.artistName.$error.required }">
<label for="artistName">Artist name</label>
<input type="text" name="artistName" id="artistName" class="form-control" ng-model="album.artistName" required />
<span ng-show="form.artistName.$dirty && form.artistName.$error.required" class="help-block">Artist name is required</span>
</div>

<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createAlbum(album)" class="btn btn-primary">Submit</button>
</div>

</form>
<form ng-show="showArtistFields">
<div class="form-group" ng-class="{ 'has-error': form.artistName.$dirty && form.artistName.$error.required }">
<label for="artistName">Artist name</label>
<input type="text" name="artistName" id="artistName" class="form-control" ng-model="artist.artistName" required />
<span ng-show="form.artistName.$dirty && form.artistName.$error.required" class="help-block">Artist name is required</span>
</div>

<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createArtist(artist)" class="btn btn-primary">Submit</button>
</div>

</form>
<form ng-show="showGenreFields">
<div class="form-group" ng-class="{ 'has-error': form.genreName.$dirty && form.genreName.$error.required }">
<label for="genreName">Genre name</label>
<input type="text" name="genreName" id="genreName" class="form-control" ng-model="genre.genreName" required />
<span ng-show="form.genreName.$dirty && form.genreName.$error.required" class="help-block">Genre name is required</span>
</div>



<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createGenre(genre.genreName)" class="btn btn-primary">Submit</button>
</div>

</form>
<form ng-show="showMediaTypeFields">
<div class="form-group" ng-class="{ 'has-error': form.mediaTypeName.$dirty && form.mediaTypeName.$error.required }">
<label for="mediaTypeName">MediaType name</label>
<input type="text" name="mediaTypeName" id="mediaTypeName" class="form-control" ng-model="mediaType.mediaTypeName" required />
<span ng-show="form.mediaTypeName.$dirty && form.mediaTypeName.$error.required" class="help-block">Media Type name is required</span>
</div>



<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createMediaType(mediaType.mediaTypeName)" class="btn btn-primary">Submit</button>
</div>

</form>






Expand Down

0 comments on commit 8d7ac36

Please sign in to comment.